library project type

This commit is contained in:
Daniel Santos 2024-12-23 15:53:26 +00:00
parent ae78170f9c
commit 3b79ef470f
6 changed files with 224 additions and 58 deletions

View file

@ -352,7 +352,6 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange";
NSArray *_objcFilesWithMain;
NSArray *_regularFilesWithMain;
NSString *_executableFileName;
BOOL _executableWasGenerated;
_srcFilesWithMain = [pcfm findSourcesWithMain: path];
_objcFilesWithMain = [pcfm filterExtensions: _srcFilesWithMain suffix: @".m" negate:false];
@ -363,19 +362,14 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange";
[projectDict setObject:_executableFileName forKey: PCPrincipalClass];
} else if ([_regularFilesWithMain count] > 0) {
_executableFileName = [_regularFilesWithMain objectAtIndex: 0];
[projectDict setObject: _executableFileName forKey: PCOtherSources];
} else {
NSString *mainFileName = [NSString stringWithFormat:@"%@_main.m", [(PCProject*)projectInstance projectName]];
// Copy the project files to the provided path
_file = [projBundle pathForResource:@"main" ofType:@"m"];
_2file = [path stringByAppendingPathComponent:
[NSString stringWithFormat:@"%@_main.m", [(PCProject*)projectInstance projectName]]];
_2file = [path stringByAppendingPathComponent: mainFileName];
[pcfm copyFile:_file toFile:_2file];
[pcfc replaceTagsInFileAtPath:_2file withProject: (PCProject*)projectInstance];
_executableFileName = [_2file lastPathComponent];
[projectDict
setObject:[NSArray arrayWithObjects: _executableFileName,nil]
forKey:PCOtherSources];
_executableWasGenerated = YES;
_executableFileName = mainFileName;
}
if (DLSA_DEBUG) {
@ -388,14 +382,11 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange";
}
[projectDict setObject: _objcFilesWithMain forKey: PCClasses];
if (!_executableWasGenerated) {
[projectDict setObject: _regularFilesWithMain forKey:PCOtherSources];
}
return _executableFileName;
}
// dlsa - search for all .m and .h files and add them to the project
- (BOOL) setSrcFilesOn: (NSMutableDictionary*)projectDict scanningFrom: (NSString*) path {
- (void) setSrcFilesOn: (NSMutableDictionary*)projectDict scanningFrom: (NSString*) path {
PCFileManager *pcfm = [PCFileManager defaultManager];
NSArray *_srcExtensionArray = [NSArray arrayWithObjects: @"m",nil];
@ -404,19 +395,15 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange";
NSMutableArray *_srcFiles = [[NSMutableArray alloc] init];
NSMutableArray *_hdrFiles = [[NSMutableArray alloc] init];
NSMutableArray *_otherSrcFiles = [[NSMutableArray alloc] init];
NSMutableArray *_gnuMakefiles = [[NSMutableArray alloc] init];
NSMutableArray *_gormFiles = [[NSMutableArray alloc] init];
NSMutableArray *_makefiles;
NSArray *_supportFiles = [[NSArray alloc] init];
BOOL moveResult = YES;
_makefiles = [projectDict objectForKey: PCSupportingFiles];
[pcfm findFilesAt: path withExtensions: _srcExtensionArray into: _srcFiles];
[pcfm findFilesAt: path withExtensions: _hdrExtensionArray into: _hdrFiles];
[pcfm findFilesAt: path withExtensions: _otherSrcsExtensionArray into: _otherSrcFiles];
if (DLSA_DEBUG) {
// print the array of files
printf("---------------------------------\n");
int idx;
for (idx = 0; idx < [_srcFiles count]; idx++) {
printf("%s\n", [[_srcFiles objectAtIndex: idx] cString]);
@ -424,38 +411,96 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange";
for (idx = 0; idx < [_hdrFiles count]; idx++) {
printf("%s\n", [[_hdrFiles objectAtIndex: idx] cString]);
}
for (idx = 0; idx < [[projectDict objectForKey: PCOtherSources] count]; idx++) {
printf("%s\n", [[[projectDict objectForKey: PCOtherSources] objectAtIndex: idx] cString]);
}
}
[projectDict setObject: _srcFiles forKey: PCClasses];
[projectDict setObject: _hdrFiles forKey: PCHeaders];
NSArray *otherSrcs = [projectDict objectForKey: PCOtherSources];
otherSrcs = [otherSrcs arrayByAddingObjectsFromArray: _otherSrcFiles];
[projectDict setObject: otherSrcs forKey: PCOtherSources];
[projectDict setObject: _gormFiles forKey: PCInterfaces];
if (DLSA_DEBUG) {
// print the array of files
printf("---------------------------------\n");
int idx;
for (idx = 0; idx < [_srcFiles count]; idx++) {
printf("%s\n", [[_srcFiles objectAtIndex: idx] cString]);
}
for (idx = 0; idx < [_hdrFiles count]; idx++) {
printf("%s\n", [[_hdrFiles objectAtIndex: idx] cString]);
}
for (idx = 0; idx < [otherSrcs count]; idx++) {
printf("%s\n", [[otherSrcs objectAtIndex: idx] cString]);
}
}
}
- (BOOL) processMakefile: (NSMutableDictionary*)projectDict scanningFrom: (NSString*) path {
PCFileManager *pcfm = [PCFileManager defaultManager];
NSMutableArray *_makefiles;
NSArray *_supportFiles = [[NSArray alloc] init];
NSMutableArray *_gnuMakefiles = [[NSMutableArray alloc] init];
BOOL _moveResult = YES;
_makefiles = [projectDict objectForKey: PCSupportingFiles];
// search for existing makefiles
[pcfm findItemsAt: path like:@"GNUmakefile" listDirectories:NO into:_gnuMakefiles];
if ([_gnuMakefiles count] > 0) {
NSString *newFileName = [[_gnuMakefiles objectAtIndex:0] stringByAppendingString: @".original"];
NSArray *oldFileNamePath = [NSArray arrayWithObjects: path, [_gnuMakefiles objectAtIndex:0], nil];
NSArray *newFileNamePath = [NSArray arrayWithObjects: path, newFileName, nil];
NSFileManager *fm = [NSFileManager defaultManager];
NSString *fromFullPath = [NSString pathWithComponents: oldFileNamePath];
NSString *toFullPath = [NSString pathWithComponents: newFileNamePath];
NSError *error;
moveResult = [fm moveItemAtPath: fromFullPath toPath: toFullPath error: &error];
if (!moveResult) {
NSRunAlertPanel(@"File Conflict",
@"The directory already contains a GNUmakefile file that cannot be moved. The Project center makefiles will not be generated",
@"Dismiss", @"Dismiss", nil);
NSString *newFileName = [[_gnuMakefiles objectAtIndex:0] stringByAppendingString: @".original"];
_moveResult = [self moveFileNamed: [_gnuMakefiles objectAtIndex:0] atPath: path toFileName: newFileName];
if (_moveResult) {
[_gnuMakefiles removeAllObjects];
[_gnuMakefiles addObject: newFileName];
[_makefiles addObjectsFromArray: _gnuMakefiles];
}
[_gnuMakefiles removeAllObjects];
[_gnuMakefiles addObject: newFileName];
[_makefiles addObjectsFromArray: _gnuMakefiles];
}
[pcfm findItemsAt: path like:@"makefile" listDirectories:NO into:_makefiles];
[pcfm findItemsAt: path like:@"Makefile" listDirectories:NO into:_makefiles];
_supportFiles = [_supportFiles arrayByAddingObjectsFromArray: _makefiles];
[projectDict setObject: _supportFiles forKey:PCSupportingFiles];
return moveResult;
return _moveResult;
}
- (BOOL) moveFileNamed: (NSString*)filename atPath: (NSString*)path toFileName: (NSString*)newFileName {
NSArray *oldFileNamePath = [NSArray arrayWithObjects: path, filename, nil];
NSArray *newFileNamePath = [NSArray arrayWithObjects: path, newFileName, nil];
NSFileManager *fm = [NSFileManager defaultManager];
NSString *fromFullPath = [NSString pathWithComponents: oldFileNamePath];
NSString *toFullPath = [NSString pathWithComponents: newFileNamePath];
BOOL _moveResult = YES;
NSError *error;
_moveResult = [fm moveItemAtPath: fromFullPath toPath: toFullPath error: &error];
return _moveResult;
}
- (void) removeEmptyEntriesFromPCOtherSources: (NSMutableDictionary*)projectDict {
NSArray *otherSrcsArray = [projectDict objectForKey: PCOtherSources];
NSMutableArray *newOtherSrcsArray = [[NSMutableArray alloc] init];
int idx;
for (idx = 0; idx < [otherSrcsArray count]; idx++) {
NSObject *element = [otherSrcsArray objectAtIndex: idx];
if ([[element className] isEqual: @"NSString"] &&
!([(NSString*)element stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString: @" "]] == @"")) {
[newOtherSrcsArray addObject: element];
}
}
[projectDict setObject: newOtherSrcsArray forKey: PCOtherSources];
if (DLSA_DEBUG) {
// print the array of files
int idx;
printf("Start ---------------------------------\n");
for (idx = 0; idx < [[projectDict objectForKey: PCOtherSources] count]; idx++) {
printf("%s\n", [[[projectDict objectForKey: PCOtherSources] objectAtIndex: idx] cString]);
}
printf("End ---------------------------------\n");
}
}
@ -961,6 +1006,8 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange";
return nil;
}
[projectCreator setProjectManager:self];
// Create project
if (!(project = [projectCreator createProjectFromSourcesAt:aPath withOption:subType]))
{
@ -970,7 +1017,6 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange";
return nil;
}
[project setProjectManager:self];
[self startSaveTimer];
return project;

View file

@ -123,7 +123,10 @@ extern NSString *PCActiveProjectDidChangeNotification;
// - dlsa - create new from sources
- (NSString*) setFileWithMainOn: (NSMutableDictionary*)projectDict scanningFrom: (NSString*)path withClass:(NSObject*)projectInstance;
- (BOOL) setSrcFilesOn: (NSMutableDictionary*)projectDict scanningFrom: (NSString*) path;
- (void) setSrcFilesOn: (NSMutableDictionary*)projectDict scanningFrom: (NSString*) path;
- (BOOL) processMakefile: (NSMutableDictionary*)projectDict scanningFrom: (NSString*) path;
- (BOOL) moveFileNamed: (NSString*)filename atPath: (NSString*)path toFileName: (NSString*)newFileName;
- (void) removeEmptyEntriesFromPCOtherSources: (NSMutableDictionary*)projectDict;
// ============================================================================
// ==== Project management

View file

@ -287,8 +287,7 @@
NSMutableArray *_subdirs = [[NSMutableArray alloc] init];
NSString *helpFile = nil;
NSString *_executableFileName;
int idx;
BOOL _moveResult = YES;
BOOL _moveResult = YES;
NSAssert(path,@"No valid project path provided!");
@ -296,6 +295,8 @@
_file = [projBundle pathForResource:@"PC" ofType:@"project"];
[projectDict initWithContentsOfFile:_file];
[projectManager removeEmptyEntriesFromPCOtherSources: projectDict];
// Customise the project
[self setProjectPath:path];
[self setProjectName: [path lastPathComponent]];
@ -316,10 +317,18 @@
_executableFileName = [projectManager setFileWithMainOn: projectDict scanningFrom: path withClass: self];
// search for all .m and .h files and add them to the project
_moveResult = [projectManager setSrcFilesOn: projectDict scanningFrom: path];
[projectManager setSrcFilesOn: projectDict scanningFrom: path];
[pcfm findDirectoriesAt: path into: _subdirs];
[projectDict setObject: _subdirs forKey: PCSubprojects];
// move an existing GNUMakefile and create the one from the template and add other makefiles
_moveResult = [projectManager processMakefile: projectDict scanningFrom:path];
if (!_moveResult) {
NSRunAlertPanel(@"File Conflict",
@"The directory already contains a GNUmakefile file that cannot be moved. The Project center makefiles will not be generated",
@"Dismiss", @"Dismiss", nil);
}
// Info-gnustep.plist
_file = [projBundle pathForResource:@"Info" ofType:@"gnustep"];
infoDict = [[NSMutableDictionary alloc] initWithContentsOfFile:_file];
@ -350,11 +359,7 @@
// GNUmakefile.postamble
[[PCMakefileFactory sharedFactory] createPostambleForProject:self];
for (idx = 0; idx < [_subdirs count]; idx++) {
NSArray *pathComps = [NSArray arrayWithObjects: path, [_subdirs objectAtIndex: idx], nil];
NSString *subdirpath = [NSString pathWithComponents: pathComps];
[self createProjectFromSourcesAt: subdirpath withOption: projOption];
}
if (_moveResult) {
[self writeMakefile];
}

View file

@ -30,6 +30,8 @@
#import <ProjectCenter/PCDefines.h>
#import <ProjectCenter/PCProject.h>
#import <Protocols/ProjectType.h>
// dlsa - create from sources
#import <ProjectCenter/PCProjectManager.h>
@class PCMakefileFactory;

View file

@ -80,6 +80,104 @@
[super dealloc];
}
// dlsa - addFromSources
- (PCProject *)createProjectFromSourcesAt: (NSString *)path withOption: (NSString *)projOption {
PCFileManager *pcfm = [PCFileManager defaultManager];
PCFileCreator *pcfc = [PCFileCreator sharedCreator];
NSString *_file = nil;
NSString *_2file = nil;
NSBundle *projBundle = [NSBundle bundleForClass:[self class]];
NSString *_resourcePath = nil;
NSMutableArray *_subdirs = [[NSMutableArray alloc] init];
BOOL _moveResult = YES;
NSAssert(path,@"No valid project path provided!");
// PC.project
_file = [projBundle pathForResource:@"PC" ofType:@"project"];
[projectDict initWithContentsOfFile:_file];
[projectManager removeEmptyEntriesFromPCOtherSources: projectDict];
// Customise the project
[self setProjectPath:path];
[self setProjectName: [path lastPathComponent]];
if ([[projectName pathExtension] isEqualToString:@"subproj"])
{
projectName = [projectName stringByDeletingPathExtension];
}
[projectDict setObject:projectName forKey:PCProjectName];
[projectDict setObject:[[NSCalendarDate date] description]
forKey:PCCreationDate];
[projectDict setObject:NSFullUserName() forKey:PCProjectCreator];
[projectDict setObject:NSFullUserName() forKey:PCProjectMaintainer];
[projectDict setObject:[NSUserDefaults userLanguages] forKey:PCUserLanguages];
// search for all .m and .h files and add them to the project
[projectManager setSrcFilesOn: projectDict scanningFrom: path];
[pcfm findDirectoriesAt: path into: _subdirs];
[projectDict setObject: _subdirs forKey: PCSubprojects];
// move an existing GNUMakefile and create the one from the template and add other makefiles
_moveResult = [projectManager processMakefile: projectDict scanningFrom:path];
if (!_moveResult) {
NSRunAlertPanel(@"File Conflict",
@"The directory already contains a GNUmakefile file that cannot be moved. The Project center makefiles will not be generated",
@"Dismiss", @"Dismiss", nil);
}
// Copy the project files to the provided path
// $PROJECTNAME$.m
_file = [NSString stringWithFormat:@"%@", projectName];
_2file = [NSString stringWithFormat:@"%@.m", projectName];
_moveResult = [projectManager moveFileNamed: _2file atPath: path toFileName: [_2file stringByAppendingString: @".original"]];
if (!_moveResult) {
NSRunAlertPanel(@"File Conflict",
[NSString stringWithFormat: @"The directory already contains a %@ file that cannot be moved. The Project center file will not be generated", _2file],
@"Dismiss", @"Dismiss", nil);
} else {
[pcfc createFileOfType:ObjCClass
path:[path stringByAppendingPathComponent:_file]
project:self];
[projectDict setObject:[NSArray arrayWithObjects:_2file,nil]
forKey:PCClasses];
}
// $PROJECTNAME$.h already created by creating $PROJECTNAME$.m
_file = [NSString stringWithFormat:@"%@.h", projectName];
_moveResult = [projectManager moveFileNamed: _file atPath: path toFileName: [_file stringByAppendingString: @".original"]];
if (!_moveResult) {
NSRunAlertPanel(@"File Conflict",
[NSString stringWithFormat: @"The directory already contains a %@ file that cannot be moved. The Project center file will not be generated", _2file],
@"Dismiss", @"Dismiss", nil);
} else {
[projectDict setObject:[NSArray arrayWithObjects:_file,nil]
forKey:PCHeaders];
[projectDict setObject:[NSArray arrayWithObjects:_file,nil]
forKey:PCPublicHeaders];
}
// GNUmakefile.postamble
[[PCMakefileFactory sharedFactory] createPostambleForProject:self];
// Resources
_resourcePath = [path stringByAppendingPathComponent:@"Resources"];
_file = [projBundle pathForResource:@"Version" ofType:@""];
_2file = [_resourcePath stringByAppendingPathComponent:@"Version"];
[pcfm copyFile:_file toFile:_2file];
if (_moveResult) {
[self writeMakefile];
}
[self save];
return self;
}
//----------------------------------------------------------------------------
// --- PCProject overridings
//----------------------------------------------------------------------------
@ -200,11 +298,6 @@
return success;
}
// dlsa - addFromSources
- (PCProject *)createProjectFromSourcesAt: (NSString *)path withOption: (NSString *)projOption {
return self;
}
@end
@implementation PCLibProject (GeneratedFiles)

View file

@ -27,6 +27,8 @@
#import <ProjectCenter/PCMakefileFactory.h>
#import <ProjectCenter/PCFileManager.h>
#import <ProjectCenter/PCFileCreator.h>
// dlsa - create from sources
#import <ProjectCenter/PCProjectManager.h>
#import "PCToolProject.h"
@ -208,11 +210,13 @@
- (PCProject *)createProjectFromSourcesAt: (NSString *)path withOption: (NSString *)projOption {
PCFileManager *pcfm = [PCFileManager defaultManager];
PCFileCreator *pcfc = [PCFileCreator sharedCreator];
NSBundle *projectBundle;
NSBundle *projectBundle;
NSString *_file;
NSString *_2file;
NSMutableArray *_array = nil;
NSString *_executableFileName;
NSMutableArray *_subdirs = [[NSMutableArray alloc] init];
BOOL _moveResult = YES;
NSAssert(path,@"No valid project path provided!");
@ -221,7 +225,7 @@
_file = [projectBundle pathForResource:@"PC" ofType:@"project"];
[projectDict initWithContentsOfFile:_file];
// search for files to add to the project
[projectManager removeEmptyEntriesFromPCOtherSources: projectDict];
// Customise the project
[self setProjectPath:path];
@ -237,11 +241,21 @@
[projectDict setObject:NSFullUserName() forKey:PCProjectMaintainer];
[projectDict setObject:[NSUserDefaults userLanguages] forKey:PCUserLanguages];
// Copy the project files to the provided path
_file = [projectBundle pathForResource:@"main" ofType:@"m"];
_2file = [path stringByAppendingPathComponent:@"main.m"];
[pcfm copyFile:_file toFile:_2file];
[pcfc replaceTagsInFileAtPath:_2file withProject:self];
// search for the main function in source files
_executableFileName = [projectManager setFileWithMainOn: projectDict scanningFrom: path withClass: self];
// search for all .m and .h files and add them to the project
[projectManager setSrcFilesOn: projectDict scanningFrom: path];
[pcfm findDirectoriesAt: path into: _subdirs];
[projectDict setObject: _subdirs forKey: PCSubprojects];
// move an existing GNUMakefile and create the one from the template and add other makefiles
_moveResult = [projectManager processMakefile: projectDict scanningFrom:path];
if (!_moveResult) {
NSRunAlertPanel(@"File Conflict",
@"The directory already contains a GNUmakefile file that cannot be moved. The Project center makefiles will not be generated",
@"Dismiss", @"Dismiss", nil);
}
// GNUmakefile.postamble
[[PCMakefileFactory sharedFactory] createPostambleForProject:self];
@ -250,6 +264,7 @@
_file = [projectBundle pathForResource:@"Info" ofType:@"gnustep"];
infoDict = [[NSMutableDictionary alloc] initWithContentsOfFile:_file];
[infoDict setObject:projectName forKey:@"ToolName"];
[infoDict setObject:_executableFileName forKey:@"NSExecutable"];
// Write to ProjectNameInfo.plist
_file = [NSString stringWithFormat:@"%@Info.plist",projectName];
@ -263,7 +278,9 @@
RELEASE(_array);
// Save the project to disc
[self writeMakefile];
if (_moveResult) {
[self writeMakefile];
}
[self save];
return self;