Java Code Examples for org.apache.maven.model.Resource#setDirectory()
The following examples show how to use
org.apache.maven.model.Resource#setDirectory() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GenerateMapperInspectionsMojo.java From syndesis with Apache License 2.0 | 6 votes |
@Override public void execute() throws MojoExecutionException, MojoFailureException { try { final Resource resource = new Resource(); resource.setDirectory(outputDir.getCanonicalPath()); project.addResource(resource); final Set<File> generated = new HashSet<>(); final ReadApiClientData reader = new ReadApiClientData(); final List<ModelData<?>> modelList = reader.readDataFromFile("io/syndesis/server/dao/deployment.json"); for (final ModelData<?> model : modelList) { if (model.getKind() == Kind.Connector) { final Connector connector = (Connector) model.getData(); for (final ConnectorAction action : connector.getActions()) { process(generated, connector, action, action.getInputDataShape()); process(generated, connector, action, action.getOutputDataShape()); } } } } catch (final IOException e) { throw new MojoFailureException(e.getMessage(), e); } }
Example 2
Source File: ResourceCopy.java From wisdom with Apache License 2.0 | 6 votes |
private static void filterAndCopy(AbstractWisdomMojo mojo, MavenResourcesFiltering filtering, File in, File out) throws IOException { Resource resource = new Resource(); resource.setDirectory(in.getAbsolutePath()); resource.setFiltering(true); resource.setTargetPath(out.getAbsolutePath()); List<String> excludedExtensions = new ArrayList<>(); excludedExtensions.addAll(filtering.getDefaultNonFilteredFileExtensions()); excludedExtensions.addAll(NON_FILTERED_EXTENSIONS); MavenResourcesExecution exec = new MavenResourcesExecution(ImmutableList.of(resource), out, mojo.project, "UTF-8", Collections.<String>emptyList(), excludedExtensions, mojo.session); exec.setEscapeString("\\"); try { filtering.filterResources(exec); } catch (MavenFilteringException e) { throw new IOException("Error while copying resources", e); } }
Example 3
Source File: AbstractProctorMojo.java From proctor with Apache License 2.0 | 6 votes |
Resource[] getResources() throws MojoExecutionException { final Resource resourceNonGenerated = new Resource(); resourceNonGenerated.setDirectory(getTopDirectory().getPath()); try { addNonPartialsToResources(getTopDirectory(),resourceNonGenerated); } catch (final CodeGenException e) { throw new MojoExecutionException("Couldn't add non partial specifications to resources"); } if (resourceNonGenerated.getIncludes().isEmpty()) { resourceNonGenerated.addExclude("**/*"); } final Resource resourceGenerated = new Resource(); final File specificationOutputDir = getSpecificationOutput(); resourceGenerated.setDirectory(specificationOutputDir.getPath()); resourceGenerated.addInclude("**/*.json"); final Resource[] resources = {resourceNonGenerated,resourceGenerated}; return resources; }
Example 4
Source File: Hyperjaxb3Mojo.java From hyperjaxb3 with BSD 2-Clause "Simplified" License | 6 votes |
/** * Updates XJC's compilePath ans resources and update hyperjaxb2's * resources, that is, *.hbm.xml files and hibernate.config.xml file. * * @param xjcOpts * @throws MojoExecutionException */ protected void setupMavenPaths() { super.setupMavenPaths(); final Resource resource = new Resource(); resource.setDirectory(getGenerateDirectory().getPath()); for (String resourceInclude : resourceIncludes) { resource.addInclude(resourceInclude); } getProject().addResource(resource); if (this.roundtripTestClassName != null) { getProject().addTestCompileSourceRoot( getGenerateDirectory().getPath()); } }
Example 5
Source File: ApiGenMojo.java From graphql-apigen with Apache License 2.0 | 5 votes |
@Override public void execute() { try { sourceDirectory = makeAbsolute(sourceDirectory); outputDirectory = makeAbsolute(outputDirectory); if ( ! sourceDirectory.exists() ) return; getLog().debug("Running ApiGen\n\tsourceDirectory=" + sourceDirectory + "\n\toutputDirectory=" + outputDirectory); ClassLoader cp = getCompileClassLoader(); ApiGen apiGen = new ApiGen.Builder() .withOutputDirectory(outputDirectory.toPath()) .withGuiceModuleName(guiceModuleName) .withDefaultPackageName(defaultPackageName) .build(); PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(cp); for ( org.springframework.core.io.Resource resource : resolver.getResources("classpath*:graphql-apigen-schema/*.graphql{,s}") ) { URL url = resource.getURL(); getLog().debug("Processing "+url); apiGen.addForReference(url); } findGraphql(sourceDirectory, apiGen::addForGeneration); apiGen.generate(); Resource schemaResource = new Resource(); schemaResource.setTargetPath("graphql-apigen-schema"); schemaResource.setFiltering(false); schemaResource.setIncludes(Arrays.asList("*.graphqls","*.graphql")); schemaResource.setDirectory(sourceDirectory.toString()); project.addResource(schemaResource); project.addCompileSourceRoot(outputDirectory.getAbsolutePath()); } catch (Exception e) { String msg = e.getMessage(); if ( null == msg ) msg = e.getClass().getName(); getLog().error(msg + " when trying to build sources from graphql.", e); } }
Example 6
Source File: AbstractScriptGeneratorMojo.java From appassembler with MIT License | 5 votes |
protected void doCopyPreAssembleDirectory( final String targetDirectory ) throws MojoFailureException { // Create a Resource from the configuration source directory Resource resource = new Resource(); resource.setDirectory( preAssembleDirectory.getAbsolutePath() ); resource.setFiltering( filterPreAssembleDirectory ); List<Resource> resources = new ArrayList<Resource>(); resources.add( resource ); MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution( resources, new File( targetDirectory ), mavenProject, encoding, buildFilters, Collections.<String>emptyList(), session ); mavenResourcesExecution.setEscapeString( escapeString ); // Include empty directories, to be backwards compatible mavenResourcesExecution.setIncludeEmptyDirs( true ); mavenResourcesExecution.setUseDefaultFilterWrappers( true ); try { getLog().info( "Copy pre-assemble files from " + this.preAssembleDirectory.getAbsolutePath() + " to " + targetDirectory ); // Use a MavenResourcesFiltering component to filter and copy the configuration files mavenResourcesFiltering.filterResources( mavenResourcesExecution ); } catch ( MavenFilteringException mfe ) { throw new MojoFailureException( "Failed to copy/filter the configuration files." ); } }
Example 7
Source File: RawXJC2Mojo.java From maven-jaxb2-plugin with BSD 2-Clause "Simplified" License | 5 votes |
/** * Augments Maven paths with generated resources. */ protected void setupMavenPaths() { if (getAddCompileSourceRoot()) { getProject().addCompileSourceRoot(getGenerateDirectory().getPath()); } if (getAddTestCompileSourceRoot()) { getProject().addTestCompileSourceRoot(getGenerateDirectory().getPath()); } if (getEpisode() && getEpisodeFile() != null) { final String episodeFilePath = getEpisodeFile().getAbsolutePath(); final String generatedDirectoryPath = getGenerateDirectory().getAbsolutePath(); if (episodeFilePath.startsWith(generatedDirectoryPath + File.separator)) { final String path = episodeFilePath.substring(generatedDirectoryPath.length() + 1); final Resource resource = new Resource(); resource.setDirectory(generatedDirectoryPath); resource.addInclude(path); if (getAddCompileSourceRoot()) { getProject().addResource(resource); } if (getAddTestCompileSourceRoot()) { getProject().addTestResource(resource); } } } }
Example 8
Source File: ResourceCopy.java From wisdom with Apache License 2.0 | 5 votes |
/** * Copies the file <tt>file</tt> to the directory <tt>dir</tt>, keeping the structure relative to <tt>rel</tt>. * * @param file the file to copy * @param rel the base 'relative' * @param dir the directory * @param mojo the mojo * @param filtering the filtering component * @param additionalProperties additional properties * @throws IOException if the file cannot be copied. */ public static void copyFileToDir(File file, File rel, File dir, AbstractWisdomMojo mojo, MavenResourcesFiltering filtering, Properties additionalProperties) throws IOException { if (filtering == null) { File out = computeRelativeFile(file, rel, dir); if (out.getParentFile() != null) { mojo.getLog().debug("Creating " + out.getParentFile() + " : " + out.getParentFile().mkdirs()); FileUtils.copyFileToDirectory(file, out.getParentFile()); } else { throw new IOException("Cannot copy file - parent directory not accessible for " + file.getAbsolutePath()); } } else { Resource resource = new Resource(); resource.setDirectory(rel.getAbsolutePath()); resource.setFiltering(true); resource.setTargetPath(dir.getAbsolutePath()); resource.setIncludes(ImmutableList.of("**/" + file.getName())); List<String> excludedExtensions = new ArrayList<>(); excludedExtensions.addAll(filtering.getDefaultNonFilteredFileExtensions()); excludedExtensions.addAll(NON_FILTERED_EXTENSIONS); MavenResourcesExecution exec = new MavenResourcesExecution(ImmutableList.of(resource), dir, mojo.project, "UTF-8", Collections.<String>emptyList(), excludedExtensions, mojo.session); if (additionalProperties != null) { exec.setAdditionalProperties(additionalProperties); } exec.setEscapeString("\\"); try { filtering.filterResources(exec); } catch (MavenFilteringException e) { throw new IOException("Error while copying resources", e); } } }
Example 9
Source File: ProjectModelEnricher.java From yaks with Apache License 2.0 | 5 votes |
/** * Dynamically add test resource directory pointing to mounted test directory. Mounted directory usually gets added * as volume mount and holds tests to execute in this project. * @param projectModel */ private void injectTestResources(Model projectModel) { if (ExtensionSettings.hasMountedTests()) { Resource mountedTests = new Resource(); mountedTests.setDirectory(ExtensionSettings.getMountedTestsPath() + "/..data"); mountedTests.setTargetPath(projectModel.getBuild().getTestOutputDirectory() + "/org/citrusframework/yaks"); mountedTests.setFiltering(false); projectModel.getBuild().getTestResources().add(mountedTests); logger.info("Add mounted test resources in directory: " + ExtensionSettings.getMountedTestsPath()); } }
Example 10
Source File: AbstractScriptGeneratorMojo.java From appassembler with MIT License | 4 votes |
protected void doCopyConfigurationDirectory( final String targetDirectory ) throws MojoFailureException { getLog().debug( "copying configuration directory." ); // Create a Resource from the configuration source directory Resource resource = new Resource(); resource.setDirectory( configurationSourceDirectory.getAbsolutePath() ); resource.setFiltering( filterConfigurationDirectory ); resource.setTargetPath( configurationDirectory ); List<Resource> resources = new ArrayList<Resource>(); resources.add( resource ); MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution( resources, new File( targetDirectory ), mavenProject, encoding, buildFilters, Collections.<String>emptyList(), session ); mavenResourcesExecution.setEscapeString( escapeString ); // Include empty directories, to be backwards compatible mavenResourcesExecution.setIncludeEmptyDirs( true ); mavenResourcesExecution.setUseDefaultFilterWrappers( true ); // @todo Possible future enhancements // mavenResourcesExecution.setEscapedBackslashesInFilePath( escapedBackslashesInFilePath ); // mavenResourcesExecution.setOverwrite( overwrite ); // mavenResourcesExecution.setSupportMultiLineFiltering( supportMultiLineFiltering ); try { getLog().debug( "Will try to copy configuration files from " + configurationSourceDirectory.getAbsolutePath() + " to " + targetDirectory + FileUtils.FS + configurationDirectory ); // Use a MavenResourcesFiltering component to filter and copy the configuration files mavenResourcesFiltering.filterResources( mavenResourcesExecution ); } catch ( MavenFilteringException mfe ) { throw new MojoFailureException( "Failed to copy/filter the configuration files." ); } }
Example 11
Source File: CreateMetadataMojo.java From buildnumber-maven-plugin with MIT License | 4 votes |
public void execute() throws MojoExecutionException, MojoFailureException { if ( skip ) { getLog().info( "Skipping execution." ); return; } Properties props = new Properties(); props.put( this.applicationPropertyName, applicationName ); props.put( this.versionPropertyName, version ); props.put( this.timestampPropertyName, Utils.createTimestamp( this.timestampFormat, timezone ) ); props.put( this.revisionPropertyName, this.getRevision() ); for ( String key : properties.keySet() ) { props.put( key, properties.get( key ) ); } File outputFile = new File( outputDirectory, outputName ); outputFiles.add( outputFile ); for ( File file : outputFiles ) { file.getParentFile().mkdirs(); writeToFile( props, file ); } if ( attach ) { projectHelper.attachArtifact( this.project, "properties", this.classifier, outputFile ); } if ( this.addOutputDirectoryToResources ) { Resource resource = new Resource(); resource.setDirectory( outputDirectory.getAbsolutePath() ); project.addResource( resource ); } }
Example 12
Source File: CreateMavenDataServicePom.java From tesb-studio-se with Apache License 2.0 | 4 votes |
private Resource addControlBundleMavenResource() { Resource resource = new Resource(); resource.addExclude("**/feature.xml"); resource.setDirectory("${basedir}/src/main/resources"); return resource; }
Example 13
Source File: GenerateTestsMojo.java From spring-cloud-contract with Apache License 2.0 | 4 votes |
@Override public void execute() throws MojoExecutionException, MojoFailureException { if (this.skip || this.mavenTestSkip || this.skipTests) { if (this.skip) { getLog().info( "Skipping Spring Cloud Contract Verifier execution: spring.cloud.contract.verifier.skip=" + this.skip); } if (this.mavenTestSkip) { getLog().info( "Skipping Spring Cloud Contract Verifier execution: maven.test.skip=" + this.mavenTestSkip); } if (this.skipTests) { getLog().info( "Skipping Spring Cloud Contract Verifier execution: skipTests" + this.skipTests); } return; } getLog().info( "Generating server tests source code for Spring Cloud Contract Verifier contract verification"); final ContractVerifierConfigProperties config = new ContractVerifierConfigProperties(); config.setFailOnInProgress(this.failOnInProgress); // download contracts, unzip them and pass as output directory File contractsDirectory = new MavenContractsDownloader(this.project, this.contractDependency, this.contractsPath, this.contractsRepositoryUrl, this.contractsMode, getLog(), this.contractsRepositoryUsername, this.contractsRepositoryPassword, this.contractsRepositoryProxyHost, this.contractsRepositoryProxyPort, this.deleteStubsAfterTest, this.contractsProperties, this.failOnNoContracts) .downloadAndUnpackContractsIfRequired(config, this.contractsDirectory); getLog().info( "Directory with contract is present at [" + contractsDirectory + "]"); if (this.incrementalContractTests && !ChangeDetector .inputFilesChangeDetected(contractsDirectory, mojoExecution, session)) { getLog().info("Nothing to generate - all classes are up to date"); return; } setupConfig(config, contractsDirectory); this.project .addTestCompileSourceRoot(this.generatedTestSourcesDir.getAbsolutePath()); Resource resource = new Resource(); resource.setDirectory(this.generatedTestResourcesDir.getAbsolutePath()); this.project.addTestResource(resource); if (getLog().isInfoEnabled()) { getLog().info("Test Source directory: " + this.generatedTestSourcesDir.getAbsolutePath() + " added."); getLog().info("Using [" + config.getBaseClassForTests() + "] as base class for test classes, [" + config.getBasePackageForTests() + "] as base " + "package for tests, [" + config.getPackageWithBaseClasses() + "] as package with " + "base classes, base class mappings " + this.baseClassMappings); } try { LeftOverPrevention leftOverPrevention = new LeftOverPrevention( this.generatedTestSourcesDir, mojoExecution, session); TestGenerator generator = new TestGenerator(config); int generatedClasses = generator.generate(); getLog().info("Generated " + generatedClasses + " test classes."); leftOverPrevention.deleteLeftOvers(); } catch (ContractVerifierException e) { throw new MojoExecutionException( String.format("Spring Cloud Contract Verifier Plugin exception: %s", e.getMessage()), e); } }
Example 14
Source File: YangProvider.java From yangtools with Eclipse Public License 1.0 | 4 votes |
static void setResource(final File targetYangDir, final MavenProject project) { Resource res = new Resource(); res.setDirectory(targetYangDir.getPath()); project.addResource(res); }
Example 15
Source File: BuildMojo.java From docker-maven-plugin with Apache License 2.0 | 4 votes |
@Override protected void execute(final DockerClient docker) throws MojoExecutionException, GitAPIException, IOException, DockerException, InterruptedException { if (weShouldSkipDockerBuild()) { getLog().info("Skipping docker build"); return; } // Put the list of exposed ports into a TreeSet which will remove duplicates and keep them // in a sorted order. This is useful when we merge with ports defined in the profile. exposesSet = Sets.newTreeSet(exposes); if (runs != null) { runList = Lists.newArrayList(runs); } expressionEvaluator = new PluginParameterExpressionEvaluator(session, execution); final Git git = new Git(); final String commitId = git.isRepository() ? git.getCommitId() : null; if (commitId == null) { final String errorMessage = "Not a git repository, cannot get commit ID. Make sure git repository is initialized."; if (useGitCommitId || ((imageName != null) && imageName.contains("${gitShortCommitId}"))) { throw new MojoExecutionException(errorMessage); } else { getLog().debug(errorMessage); } } else { // Put the git commit id in the project properties. Image names may contain // ${gitShortCommitId} in which case we want to fill in the actual value using the // expression evaluator. We will do that once here for image names loaded from the pom, // and again in the loadProfile method when we load values from the profile. mavenProject.getProperties().put("gitShortCommitId", commitId); if (imageName != null) { imageName = expand(imageName); } if (baseImage != null) { baseImage = expand(baseImage); } } loadProfile(); validateParameters(); final String[] repoTag = parseImageName(imageName); final String repo = repoTag[0]; final String tag = repoTag[1]; if (useGitCommitId) { if (tag != null) { getLog().warn("Ignoring useGitCommitId flag because tag is explicitly set in image name "); } else if (commitId == null) { throw new MojoExecutionException( "Cannot tag with git commit ID because directory not a git repo"); } else { imageName = repo + ":" + commitId; } } mavenProject.getProperties().put("imageName", imageName); final String destination = getDestination(); if (dockerDirectory == null) { final List<String> copiedPaths = copyResources(destination); createDockerFile(destination, copiedPaths); } else { final Resource resource = new Resource(); resource.setDirectory(dockerDirectory); resources.add(resource); copyResources(destination); } buildImage(docker, destination, buildParams()); tagImage(docker, forceTags); final DockerBuildInformation buildInfo = new DockerBuildInformation(imageName, getLog()); if ("docker".equals(mavenProject.getPackaging())) { final File imageArtifact = createImageArtifact(mavenProject.getArtifact(), buildInfo); mavenProject.getArtifact().setFile(imageArtifact); } // Push specific tags specified in pom rather than all images if (pushImageTag) { pushImageTag(docker, imageName, imageTags, getLog(), isSkipDockerPush()); } if (pushImage) { pushImage(docker, imageName, imageTags, getLog(), buildInfo, getRetryPushCount(), getRetryPushTimeout(), isSkipDockerPush()); } if (saveImageToTarArchive != null) { saveImage(docker, imageName, Paths.get(saveImageToTarArchive), getLog()); } // Write image info file writeImageInfoFile(buildInfo, tagInfoFile); }
Example 16
Source File: CopyContracts.java From spring-cloud-contract with Apache License 2.0 | 4 votes |
public void copy(File contractsDirectory, File outputDirectory) throws MojoExecutionException { log.info("Copying Spring Cloud Contract Verifier contracts to [" + outputDirectory + "]" + ". Only files matching [" + this.config.getIncludedContracts() + "] pattern will end up in " + "the final JAR with stubs."); Resource resource = new Resource(); String includedRootFolderAntPattern = this.config .getIncludedRootFolderAntPattern() + "*.*"; String slashSeparatedGroupIdAntPattern = slashSeparatedGroupIdAntPattern( includedRootFolderAntPattern); String dotSeparatedGroupIdAntPattern = dotSeparatedGroupIdAntPattern( includedRootFolderAntPattern); // by default group id is slash separated... resource.addInclude(slashSeparatedGroupIdAntPattern); if (!slashSeparatedGroupIdAntPattern.equals(dotSeparatedGroupIdAntPattern)) { // ...we also want to allow dot separation resource.addInclude(dotSeparatedGroupIdAntPattern); } if (this.config.isExcludeBuildFolders()) { resource.addExclude("**/target/**"); resource.addExclude("**/.mvn/**"); resource.addExclude("**/build/**"); resource.addExclude("**/.gradle/**"); } resource.setDirectory(contractsDirectory.getAbsolutePath()); MavenResourcesExecution execution = new MavenResourcesExecution(); execution.setResources(Collections.singletonList(resource)); execution.setOutputDirectory(outputDirectory); execution.setMavenProject(this.project); execution.setEncoding("UTF-8"); execution.setMavenSession(this.mavenSession); execution.setInjectProjectBuildFilters(false); execution.setOverwrite(true); execution.setIncludeEmptyDirs(false); execution.setFilterFilenames(false); execution.setFilters(Collections.emptyList()); try { this.mavenResourcesFiltering.filterResources(execution); } catch (MavenFilteringException e) { throw new MojoExecutionException(e.getMessage(), e); } }
Example 17
Source File: ResourceCompilerMojo.java From sis with Apache License 2.0 | 4 votes |
/** * Declares {@link #outputDirectory} as resource, for inclusion by Maven in the JAR file. */ private void declareOutputDirectory() { final Resource resource = new Resource(); resource.setDirectory(outputDirectory.getPath()); project.addResource(resource); }
Example 18
Source File: MdPageGeneratorMojo.java From markdown-page-generator-plugin with MIT License | 4 votes |
private void performMavenPropertyFiltering(final File inputDirectory, final File outputDirectory, final String inputEncoding) throws MojoExecutionException { try { List<String> combinedFilters = getCombinedFiltersList(); List<Resource> resources = new ArrayList<>(); final Resource resource = new Resource(); resource.setFiltering(true); resource.setDirectory(inputDirectory.getAbsolutePath()); resources.add(resource); MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution( resources, outputDirectory, project, this.inputEncoding, combinedFilters, Collections.<String>emptyList(), session ); // mavenResourcesExecution.setEscapeWindowsPaths(escapeWindowsPaths); // never include project build filters in this call, since we've already accounted for the POM build filters // above, in getCombinedFiltersList(). mavenResourcesExecution.setInjectProjectBuildFilters(false); // mavenResourcesExecution.setEscapeString(escapeString); mavenResourcesExecution.setOverwrite(true); // mavenResourcesExecution.setIncludeEmptyDirs(includeEmptyDirs); // mavenResourcesExecution.setSupportMultiLineFiltering(supportMultiLineFiltering); // mavenResourcesExecution.setFilterFilenames(fileNameFiltering); mavenResourcesExecution.setAddDefaultExcludes(addDefaultExcludes); // Handle subject of MRESOURCES-99 Properties additionalProperties = addSeveralSpecialProperties(); mavenResourcesExecution.setAdditionalProperties(additionalProperties); // if these are NOT set, just use the defaults, which are '${*}' and '@'. // mavenResourcesExecution.setDelimiters(delimiters, useDefaultDelimiters); if (nonFilteredFileExtensions != null) { mavenResourcesExecution.setNonFilteredFileExtensions(nonFilteredFileExtensions); } mavenResourcesFiltering.filterResources(mavenResourcesExecution); executeUserFilterComponents(mavenResourcesExecution); mavenResourcesExecution.getOutputDirectory(); } catch (MavenFilteringException e) { throw new MojoExecutionException("Failure while processing/filtering markdown sources: " + e.getMessage(), e); } }