@Override public Path resolvePackage( final Path resource ) { //Null resource paths cannot resolve to a Project if ( resource == null ) { return null; } //If Path is not within a Project we cannot resolve a package final Path projectRoot = resolveProject( resource ); if ( projectRoot == null ) { return null; } //Check whether path is a Src package or a Test package Path packagePath = doResolveSrcPackage( resource, projectRoot ); if ( packagePath == null ) { packagePath = doResolveTestPackage( resource, projectRoot ); } return packagePath; }
@Override public Path newPackage( final Path contextPath, final String packageName ) { return newDirectory( contextPath, packageName ); }
@Override public Path resolveTestPackage( final Path resource ) { //Null resource paths cannot resolve to a Project if ( resource == null ) { return null; } //If Path is not within a Project we cannot resolve a package final Path projectRoot = resolveProject( resource ); if ( projectRoot == null ) { return null; } return doResolveTestPackage( resource, projectRoot ); }
@Override public Path resolveSrcPackage( final Path resource ) { //Null resource paths cannot resolve to a Project if ( resource == null ) { return null; } //If Path is not within a Project we cannot resolve a package final Path projectRoot = resolveProject( resource ); if ( projectRoot == null ) { return null; } return doResolveSrcPackage( resource, projectRoot ); }
private Path doResolveSrcPackage( final Path resource, final Path projectRoot ) { //The pom.xml and kmodule.xml files are not within a package if ( isPom( resource ) || isKModule( resource ) ) { return null; } //The Path must be within a Project's src/main/java or src/main/resources path boolean resolved = false; org.kie.commons.java.nio.file.Path path = paths.convert( resource ).normalize(); final org.kie.commons.java.nio.file.Path srcJavaPath = paths.convert( projectRoot ).resolve( SOURCE_JAVA_PATH ); final org.kie.commons.java.nio.file.Path srcResourcesPath = paths.convert( projectRoot ).resolve( SOURCE_RESOURCES_PATH ); //Check if path resides within a Java or Resources path if ( path.startsWith( srcJavaPath ) ) { resolved = true; } else if ( path.startsWith( srcResourcesPath ) ) { resolved = true; } if ( !resolved ) { return null; } //If the Path is already a folder simply return it if ( Files.isDirectory( path ) ) { return resource; } path = path.getParent(); return paths.convert( path ); }
path = path.getParent(); if ( hasPom( path ) && hasKModule( path ) ) { return paths.convert( path ); return null; if ( !hasPom( path ) ) { return null; if ( !hasKModule( path ) ) { return null;
@Override public Path newProject( final Path activePath, final String projectName, final String baseURL ) { //Projects are always created in the FS root final Path fsRoot = getFileSystemRoot( activePath ); final Path projectRootPath = getProjectRootPath( fsRoot, projectName ); //Set-up project structure and KModule.xml kModuleService.setUpKModuleStructure( projectRootPath ); //Create POM.xml pomService.create( projectRootPath, baseURL ); //Create Project configuration final Path projectConfigPath = paths.convert( paths.convert( projectRootPath ).resolve( "project.imports" ), false ); ioService.createFile( paths.convert( projectConfigPath ) ); ioService.write( paths.convert( projectConfigPath ), packageConfigurationContentHandler.toString( new PackageConfiguration() ) ); //Signal creation to interested parties resourceAddedEvent.fire( new ResourceAddedEvent( projectRootPath ) ); return paths.convert( paths.convert( projectRootPath ).resolve( "pom.xml" ) ); }
@Override public Path save( final Path resource, final PackageConfiguration packageConfiguration, final Metadata metadata, final String comment ) { ioService.write( paths.convert( resource ), packageConfigurationContentHandler.toString( packageConfiguration ), metadataService.setUpAttributes( resource, metadata ), makeCommentedOption( comment ) ); //Invalidate Project-level DMO cache as project.imports has changed. invalidateDMOProjectCache.fire( new InvalidateDMOProjectCacheEvent( resource ) ); //Signal update to interested parties resourceUpdatedEvent.fire( new ResourceUpdatedEvent( resource ) ); return resource; }
private Path doResolveTestPackage( final Path resource, final Path projectRoot ) { //The pom.xml and kmodule.xml files are not within a package if ( isPom( resource ) || isKModule( resource ) ) { return null; } //The Path must be within a Project's src/test/java or src/test/resources path boolean resolved = false; org.kie.commons.java.nio.file.Path path = paths.convert( resource ).normalize(); final org.kie.commons.java.nio.file.Path testJavaPath = paths.convert( projectRoot ).resolve( TEST_JAVA_PATH ); final org.kie.commons.java.nio.file.Path testResourcesPath = paths.convert( projectRoot ).resolve( TEST_RESOURCES_PATH ); //Check if path resides within a Java or Resources path if ( path.startsWith( testJavaPath ) ) { resolved = true; } else if ( path.startsWith( testResourcesPath ) ) { resolved = true; } if ( !resolved ) { return null; } //If the Path is already a folder simply return it if ( Files.isDirectory( path ) ) { return resource; } path = path.getParent(); return paths.convert( path ); }