@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 ); }
@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; }
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 ); }
@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; }
@Override public Path save( final Path path, final POM content, final Metadata metadata, final String comment ) { try { if ( metadata == null ) { ioService.write( paths.convert( path ), pomContentHandler.toString( content ), makeCommentedOption( comment ) ); } else { ioService.write( paths.convert( path ), pomContentHandler.toString( content ), metadataService.setUpAttributes( path, metadata ), makeCommentedOption( comment ) ); } //Invalidate Project-level DMO cache as POM has changed. invalidateDMOProjectCache.fire( new InvalidateDMOProjectCacheEvent( path ) ); //Signal update to interested parties resourceUpdatedEvent.fire( new ResourceUpdatedEvent( path ) ); return path; } catch ( IOException e ) { throw new org.kie.commons.java.nio.IOException( e.getMessage() ); } }
@Override public Path resolvePathToPom( final Path resource ) { final Path projectPath = resolveProject( resource ); if ( projectPath == null ) { return null; } final org.kie.commons.java.nio.file.Path pom = paths.convert( projectPath ).resolve( POM_PATH ); if ( pom == null ) { return null; } return paths.convert( pom ); }
public String toString(PackageConfiguration configuration) { return createXStream().toXML(configuration); }
public String toString(KModuleModel model) { return createXStream().toXML(model); }
@Override public KModuleModel load( final Path path ) { final org.kie.commons.java.nio.file.Path nioPath = paths.convert( path ); final String content = ioService.readAllString( nioPath ); return moduleContentHandler.toModel( content ); }
@Override public PackageConfiguration load( final Path path ) { final String content = ioService.readAllString( paths.convert( path ) ); return packageConfigurationContentHandler.toModel( content ); }
@Override public POM load( final Path path ) { try { final org.kie.commons.java.nio.file.Path nioPath = paths.convert( path ); final String content = ioService.readAllString( nioPath ); return pomContentHandler.toModel( content ); } catch ( IOException e ) { throw new org.kie.commons.java.nio.IOException( e.getMessage() ); } catch ( XmlPullParserException e ) { throw new org.kie.commons.java.nio.IOException( e.getMessage() ); } }
public String toString(POM gavModel) throws IOException { Model model = new Model(); model.setGroupId(gavModel.getGav().getGroupId()); model.setArtifactId(gavModel.getGav().getArtifactId()); model.setVersion(gavModel.getGav().getVersion()); model.setModelVersion(gavModel.getModelVersion()); for (org.kie.guvnor.project.model.Repository repository : gavModel.getRepositories()) { model.addRepository(fromClientModelToPom(repository)); } for (org.kie.guvnor.project.model.Dependency dependency : gavModel.getDependencies()) { model.addDependency(fromClientModelToPom(dependency)); } StringWriter stringWriter = new StringWriter(); new MavenXpp3Writer().write(stringWriter, model); return stringWriter.toString(); }
@Override public Path setUpKModuleStructure( final Path projectRoot ) { // Create project structure final org.kie.commons.java.nio.file.Path nioRoot = paths.convert( projectRoot ); ioService.createDirectory( nioRoot.resolve( "src/main/java" ) ); ioService.createDirectory( nioRoot.resolve( "src/main/resources" ) ); ioService.createDirectory( nioRoot.resolve( "src/test/java" ) ); ioService.createDirectory( nioRoot.resolve( "src/test/resources" ) ); final org.kie.commons.java.nio.file.Path pathToKModuleXML = nioRoot.resolve( "src/main/resources/META-INF/kmodule.xml" ); ioService.createFile( pathToKModuleXML ); ioService.write( pathToKModuleXML, moduleContentHandler.toString( new KModuleModel() ) ); //Don't raise a NewResourceAdded event as this is handled at the Project level in ProjectServices return paths.convert( pathToKModuleXML ); }
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 ); }
@Override public boolean isPom( final Path resource ) { //Null resource paths cannot resolve to a Project if ( resource == null ) { return false; } //Check if path equals pom.xml final Path projectRoot = resolveProject( resource ); final org.kie.commons.java.nio.file.Path path = paths.convert( resource ).normalize(); final org.kie.commons.java.nio.file.Path pomFilePath = paths.convert( projectRoot ).resolve( POM_PATH ); return path.startsWith( pomFilePath ); }
public PackageConfiguration toModel(String text) { return (PackageConfiguration) createXStream().fromXML(text); }
public KModuleModel toModel(String xml) { return (KModuleModel) createXStream().fromXML(xml); }
@Override public boolean isKModule( final Path resource ) { //Null resource paths cannot resolve to a Project if ( resource == null ) { return false; } //Check if path equals kmodule.xml final Path projectRoot = resolveProject( resource ); final org.kie.commons.java.nio.file.Path path = paths.convert( resource ).normalize(); final org.kie.commons.java.nio.file.Path kmoduleFilePath = paths.convert( projectRoot ).resolve( KMODULE_PATH ); return path.startsWith( kmoduleFilePath ); }