org.apache.maven.lifecycle.LifecycleExecutionException Java Examples
The following examples show how to use
org.apache.maven.lifecycle.LifecycleExecutionException.
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: MutableMojo.java From java-specialagent with Apache License 2.0 | 6 votes |
static void resolveDependencies(final MavenSession session, final MojoExecution execution, final MojoExecutor executor, final ProjectDependenciesResolver projectDependenciesResolver) throws DependencyResolutionException, LifecycleExecutionException { // flushProjectArtifactsCache(executor); final MavenProject project = session.getCurrentProject(); final Set<Artifact> dependencyArtifacts = project.getDependencyArtifacts(); final Map<String,List<MojoExecution>> executions = new LinkedHashMap<>(execution.getForkedExecutions()); final ExecutionListener executionListener = session.getRequest().getExecutionListener(); try { project.setDependencyArtifacts(null); execution.getForkedExecutions().clear(); session.getRequest().setExecutionListener(null); executor.execute(session, Collections.singletonList(execution), new ProjectIndex(session.getProjects())); } finally { execution.getForkedExecutions().putAll(executions); session.getRequest().setExecutionListener(executionListener); project.setDependencyArtifacts(dependencyArtifacts); } projectDependenciesResolver.resolve(newDefaultDependencyResolutionRequest(session)); }
Example #2
Source File: YamlFileDependencyLoader.java From yaks with Apache License 2.0 | 6 votes |
@Override protected List<Dependency> load(Path filePath, Properties properties, Logger logger) throws LifecycleExecutionException { try { List<Dependency> dependencyList = new ArrayList<>(); Yaml yaml = new Yaml(); HashMap<String, List<Map<String, Object>>> root = yaml.load(new StringReader(new String(Files.readAllBytes(filePath), StandardCharsets.UTF_8))); if (root.containsKey("dependencies")) { for (Map<String, Object> coordinates : root.get("dependencies")) { Dependency dependency = new Dependency(); dependency.setGroupId(Objects.toString(coordinates.get("groupId"))); dependency.setArtifactId(Objects.toString(coordinates.get("artifactId"))); dependency.setVersion(resolveVersionProperty(Objects.toString(coordinates.get("version")), properties)); logger.info(String.format("Add %s", dependency)); dependencyList.add(dependency); } } return dependencyList; } catch (IOException e) { throw new LifecycleExecutionException("Failed to read dependency configuration file", e); } }
Example #3
Source File: MojoExecutor.java From dew with Apache License 2.0 | 6 votes |
public void execute( MavenSession session, List<MojoExecution> mojoExecutions, ProjectIndex projectIndex ) throws LifecycleExecutionException { if (SkipCheck.skip(session.getCurrentProject().getBasedir()) && mojoExecutions.stream().map(MojoExecution::getGoal).map(String::toLowerCase) .anyMatch(s -> s.contains("group.idealworld.dew:dew-maven-plugin:release") || s.contains("dew:release") || s.contains("deploy"))) { return; } DependencyContext dependencyContext = newDependencyContext( session, mojoExecutions ); PhaseRecorder phaseRecorder = new PhaseRecorder( session.getCurrentProject() ); for ( MojoExecution mojoExecution : mojoExecutions ) { execute( session, mojoExecution, projectIndex, dependencyContext, phaseRecorder ); } }
Example #4
Source File: FeatureTagsDependencyLoader.java From yaks with Apache License 2.0 | 6 votes |
/** * Load all dependencies specified through BDD tag information in given feature file content. * @param feature * @param properties * @param logger * @return */ private List<Dependency> loadDependencyTags(String feature, Properties properties, Logger logger) { return new BufferedReader(new StringReader(feature)) .lines() .map(TAG_PATTERN::matcher) .filter(Matcher::matches) .map(matcher -> { try { return build(matcher.group("coordinate"), properties, logger); } catch (LifecycleExecutionException e) { logger.error("Failed to read dependency tag information", e); return null; } }) .filter(Objects::nonNull) .collect(Collectors.toList()); }
Example #5
Source File: EnvironmentSettingRepositoryLoader.java From yaks with Apache License 2.0 | 6 votes |
@Override public List<Repository> load(Logger logger) throws LifecycleExecutionException { List<Repository> repositoryList = new ArrayList<>(); String settings = getEnvSetting(ExtensionSettings.REPOSITORIES_SETTING_ENV); if (settings.length() > 0) { for (String scalar : settings.split(",")) { String[] config = scalar.split("="); if (config.length == 2) { repositoryList.add(build(config[0], config[1], logger)); } } if (!repositoryList.isEmpty()) { logger.info(String.format("Add %s repositories found in environment variables", repositoryList.size())); } } return repositoryList; }
Example #6
Source File: EnvironmentSettingDependencyLoader.java From yaks with Apache License 2.0 | 6 votes |
@Override public List<Dependency> load(Properties properties, Logger logger) throws LifecycleExecutionException { List<Dependency> dependencyList = new ArrayList<>(); String coordinates = getEnvSetting(ExtensionSettings.DEPENDENCIES_SETTING_ENV); if (coordinates.length() > 0) { for (String coordinate : coordinates.split(",")) { dependencyList.add(build(coordinate, properties, logger)); } if (!dependencyList.isEmpty()) { logger.info(String.format("Add %s dependencies found in environment variables", dependencyList.size())); } } return dependencyList; }
Example #7
Source File: JsonFileDependencyLoader.java From yaks with Apache License 2.0 | 6 votes |
@Override protected List<Dependency> load(Path filePath, Properties properties, Logger logger) throws LifecycleExecutionException { List<Dependency> dependencyList = new ArrayList<>(); ObjectMapper mapper = new ObjectMapper(); try { JsonNode root = mapper.readTree(new StringReader(new String(Files.readAllBytes(filePath), StandardCharsets.UTF_8))); ArrayNode dependencies = (ArrayNode) root.get("dependencies"); for (Object o : dependencies) { ObjectNode coordinates = (ObjectNode) o; Dependency dependency = new Dependency(); dependency.setGroupId(coordinates.get("groupId").textValue()); dependency.setArtifactId(coordinates.get("artifactId").textValue()); dependency.setVersion(resolveVersionProperty(coordinates.get("version").textValue(), properties)); logger.info(String.format("Add %s", dependency)); dependencyList.add(dependency); } } catch (IOException e) { throw new LifecycleExecutionException("Failed to read json dependency config file", e); } return dependencyList; }
Example #8
Source File: SystemPropertyDependencyLoader.java From yaks with Apache License 2.0 | 6 votes |
@Override public List<Dependency> load(Properties properties, Logger logger) throws LifecycleExecutionException { List<Dependency> dependencyList = new ArrayList<>(); String coordinates = System.getProperty(ExtensionSettings.DEPENDENCIES_SETTING_KEY, ""); if (coordinates.length() > 0) { for (String coordinate : coordinates.split(",")) { dependencyList.add(build(coordinate, properties, logger)); } if (!dependencyList.isEmpty()) { logger.info(String.format("Add %s dependencies found in system properties", dependencyList.size())); } } return dependencyList; }
Example #9
Source File: SystemPropertyRepositoryLoader.java From yaks with Apache License 2.0 | 6 votes |
@Override public List<Repository> load(Logger logger) throws LifecycleExecutionException { List<Repository> repositoryList = new ArrayList<>(); String coordinates = System.getProperty(ExtensionSettings.REPOSITORIES_SETTING_KEY, ""); if (coordinates.length() > 0) { for (String scalar : coordinates.split(",")) { String[] config = scalar.split("="); if (config.length == 2) { repositoryList.add(build(config[0], config[1], logger)); } } if (!repositoryList.isEmpty()) { logger.info(String.format("Add %s repositories found in system properties", repositoryList.size())); } } return repositoryList; }
Example #10
Source File: MojoExecutor.java From dew with Apache License 2.0 | 6 votes |
public void execute( MavenSession session, List<MojoExecution> mojoExecutions, ProjectIndex projectIndex ) throws LifecycleExecutionException { if (SkipCheck.skip(session.getCurrentProject().getBasedir()) && mojoExecutions.stream().map(MojoExecution::getGoal).map(String::toLowerCase) .anyMatch(s -> s.contains("group.idealworld.dew:dew-maven-plugin:release") || s.contains("dew:release") || s.contains("deploy"))) { return; } DependencyContext dependencyContext = newDependencyContext( session, mojoExecutions ); PhaseRecorder phaseRecorder = new PhaseRecorder( session.getCurrentProject() ); for ( MojoExecution mojoExecution : mojoExecutions ) { execute( session, mojoExecution, projectIndex, dependencyContext, phaseRecorder ); } }
Example #11
Source File: FileBasedDependencyLoader.java From yaks with Apache License 2.0 | 6 votes |
public static Path getSettingsFile() throws LifecycleExecutionException { String filePath = ExtensionSettings.getSettingsFilePath(); if (filePath.startsWith("classpath:")) { try { URL resourceUrl = FileBasedDependencyLoader.class.getClassLoader().getResource(filePath.substring("classpath:".length())); if (resourceUrl != null) { return Paths.get(resourceUrl.toURI()); } } catch (URISyntaxException e) { throw new LifecycleExecutionException("Unable to locate properties file in classpath", e); } } else if (filePath.startsWith("file:")) { return Paths.get(filePath.substring("file:".length())); } return Paths.get(filePath); }
Example #12
Source File: FileBasedRepositoryLoader.java From yaks with Apache License 2.0 | 6 votes |
public static Path getSettingsFile() throws LifecycleExecutionException { String filePath = ExtensionSettings.getSettingsFilePath(); if (filePath.startsWith("classpath:")) { try { URL resourceUrl = FileBasedRepositoryLoader.class.getClassLoader().getResource(filePath.substring("classpath:".length())); if (resourceUrl != null) { return Paths.get(resourceUrl.toURI()); } } catch (URISyntaxException e) { throw new LifecycleExecutionException("Unable to locate properties file in classpath", e); } } else if (filePath.startsWith("file:")) { return Paths.get(filePath.substring("file:".length())); } return Paths.get(filePath); }
Example #13
Source File: DisplayPluginUpdatesMojo.java From versions-maven-plugin with Apache License 2.0 | 6 votes |
/** * Gets the phase to lifecycle map. * * @param lifecycles The list of lifecycles. * @return the phase to lifecycle map. * @throws LifecycleExecutionException the lifecycle execution exception. */ public Map<String, Lifecycle> getPhaseToLifecycleMap( List<Lifecycle> lifecycles ) throws LifecycleExecutionException { Map<String, Lifecycle> phaseToLifecycleMap = new HashMap<>(); for ( Lifecycle lifecycle : lifecycles ) { for ( String phase : (List<String>) lifecycle.getPhases() ) { if ( phaseToLifecycleMap.containsKey( phase ) ) { Lifecycle prevLifecycle = phaseToLifecycleMap.get( phase ); throw new LifecycleExecutionException( "Phase '" + phase + "' is defined in more than one lifecycle: '" + lifecycle.getId() + "' and '" + prevLifecycle.getId() + "'" ); } else { phaseToLifecycleMap.put( phase, lifecycle ); } } } return phaseToLifecycleMap; }
Example #14
Source File: CompatibilityTestMojo.java From java-specialagent with Apache License 2.0 | 6 votes |
private void assertCompatibility(final Dependency[] dependencies, final boolean shouldPass) throws DependencyResolutionException, IOException, LifecycleExecutionException, MojoExecutionException { final Dependency[] rollback = replaceDependencies(getProject().getDependencies(), dependencies); getLog().info("|-- " + print(dependencies)); resolveDependencies(); final List<URL> classpath = new ArrayList<>(); for (final Artifact artifact : getProject().getArtifacts()) classpath.add(AssembleUtil.toURL(MavenUtil.getPathOf(localRepository.getBasedir(), artifact))); if (isDebug()) getLog().warn(classpath.toString()); try (final URLClassLoader classLoader = new URLClassLoader(classpath.toArray(new URL[classpath.size()]), null)) { final LibraryFingerprint fingerprint = LibraryFingerprint.fromFile(new File(getProject().getBuild().getOutputDirectory(), UtilConstants.FINGERPRINT_FILE).toURI().toURL()); final List<FingerprintError> errors = fingerprint.isCompatible(classLoader); if (errors == null != shouldPass) { final String error = print(dependencies) + " should have " + (errors == null ? "failed" : "passed:\n" + AssembleUtil.toIndentedString(errors)); if (failAtEnd) this.errors.add(error); else throw new MojoExecutionException(error + "\nClasspath:\n" + AssembleUtil.toIndentedString(classpath)); } } rollbackDependencies(getProject().getDependencies(), rollback); }
Example #15
Source File: MojoExecutor.java From dew with Apache License 2.0 | 6 votes |
public void execute( MavenSession session, List<MojoExecution> mojoExecutions, ProjectIndex projectIndex ) throws LifecycleExecutionException { if (SkipCheck.skip(session.getCurrentProject().getBasedir()) && mojoExecutions.stream().map(MojoExecution::getGoal).map(String::toLowerCase) .anyMatch(s -> s.contains("group.idealworld.dew:dew-maven-plugin:release") || s.contains("dew:release") || s.contains("deploy"))) { return; } DependencyContext dependencyContext = newDependencyContext( session, mojoExecutions ); PhaseRecorder phaseRecorder = new PhaseRecorder( session.getCurrentProject() ); for ( MojoExecution mojoExecution : mojoExecutions ) { execute( session, mojoExecution, projectIndex, dependencyContext, phaseRecorder ); } }
Example #16
Source File: MojoExecutor.java From dew with Apache License 2.0 | 6 votes |
public void execute( MavenSession session, List<MojoExecution> mojoExecutions, ProjectIndex projectIndex ) throws LifecycleExecutionException { if (SkipCheck.skip(session.getCurrentProject().getBasedir()) && mojoExecutions.stream().map(MojoExecution::getGoal).map(String::toLowerCase) .anyMatch(s -> s.contains("group.idealworld.dew:dew-maven-plugin:release") || s.contains("dew:release") || s.contains("deploy"))) { return; } DependencyContext dependencyContext = newDependencyContext( session, mojoExecutions ); PhaseRecorder phaseRecorder = new PhaseRecorder( session.getCurrentProject() ); for ( MojoExecution mojoExecution : mojoExecutions ) { execute( session, mojoExecution, projectIndex, dependencyContext, phaseRecorder ); } }
Example #17
Source File: ProjectModelReader.java From yaks with Apache License 2.0 | 6 votes |
/** * Dynamically add project repositories based on different configuration sources such as environment variables, * system properties configuration files. */ private List<Repository> loadDynamicRepositories() { if (repositoryList == null) { repositoryList = new ArrayList<>(); logger.info("Add dynamic project repositories ..."); try { repositoryList.addAll(new FileBasedRepositoryLoader().load(logger)); repositoryList.addAll(new SystemPropertyRepositoryLoader().load(logger)); repositoryList.addAll(new EnvironmentSettingRepositoryLoader().load(logger)); } catch (LifecycleExecutionException e) { throw new RuntimeException(e); } } return repositoryList; }
Example #18
Source File: MojoExecutor.java From dew with Apache License 2.0 | 6 votes |
public void execute( MavenSession session, List<MojoExecution> mojoExecutions, ProjectIndex projectIndex ) throws LifecycleExecutionException { if (SkipCheck.skip(session.getCurrentProject().getBasedir()) && mojoExecutions.stream().map(MojoExecution::getGoal).map(String::toLowerCase) .anyMatch(s -> s.contains("group.idealworld.dew:dew-maven-plugin:release") || s.contains("dew:release") || s.contains("deploy"))) { return; } DependencyContext dependencyContext = newDependencyContext( session, mojoExecutions ); PhaseRecorder phaseRecorder = new PhaseRecorder( session.getCurrentProject() ); for ( MojoExecution mojoExecution : mojoExecutions ) { execute( session, mojoExecution, projectIndex, dependencyContext, phaseRecorder ); } }
Example #19
Source File: DependencyLoader.java From yaks with Apache License 2.0 | 6 votes |
/** * Construct dependency form coordinate string that follows the format "groupId:artifactId:version". Coordinates must * have a version set. * @param coordinates * @param properties * @param logger * @return */ default Dependency build(String coordinates, Properties properties, Logger logger) throws LifecycleExecutionException { Dependency dependency = new Dependency(); Matcher matcher = COORDINATE_PATTERN.matcher(coordinates); if (!matcher.matches()) { throw new LifecycleExecutionException("Unsupported dependency coordinate. Must be of format groupId:artifactId:version"); } String groupId = matcher.group("groupId"); String artifactId = matcher.group("artifactId"); String version = resolveVersionProperty(matcher.group("version"), properties); dependency.setGroupId(groupId); dependency.setArtifactId(artifactId); dependency.setVersion(version); logger.info(String.format("Add %s", dependency)); return dependency; }
Example #20
Source File: MojoExecutor.java From dew with Apache License 2.0 | 6 votes |
public void execute( MavenSession session, List<MojoExecution> mojoExecutions, ProjectIndex projectIndex ) throws LifecycleExecutionException { if (SkipCheck.skip(session.getCurrentProject().getBasedir()) && mojoExecutions.stream().map(MojoExecution::getGoal).map(String::toLowerCase) .anyMatch(s -> s.contains("group.idealworld.dew:dew-maven-plugin:release") || s.contains("dew:release") || s.contains("deploy"))) { return; } DependencyContext dependencyContext = newDependencyContext( session, mojoExecutions ); PhaseRecorder phaseRecorder = new PhaseRecorder( session.getCurrentProject() ); for ( MojoExecution mojoExecution : mojoExecutions ) { execute( session, mojoExecution, projectIndex, dependencyContext, phaseRecorder ); } }
Example #21
Source File: RepositoryLoader.java From yaks with Apache License 2.0 | 6 votes |
/** * Construct repository instance from given url. Query parameters are translated to fields on the target repository. * @param id * @param url * @param logger * @return */ default Repository build(String id, String url, Logger logger) throws LifecycleExecutionException { Repository repository = new Repository(); repository.setId(id); try { URL configurationUrl = new URL(url); repository.setUrl(String.format("%s://%s%s", configurationUrl.getProtocol(), configurationUrl.getHost(), configurationUrl.getPath())); } catch (MalformedURLException e) { throw new LifecycleExecutionException("Failed to construct Maven repository model from given URL", e); } logger.info(String.format("Add Repository %s=%s", repository.getId(), repository.getUrl())); return repository; }
Example #22
Source File: MojoExecutor.java From dew with Apache License 2.0 | 6 votes |
public void execute(MavenSession session, List<MojoExecution> mojoExecutions, ProjectIndex projectIndex) throws LifecycleExecutionException { if (SkipCheck.skip(session.getCurrentProject().getBasedir()) && mojoExecutions.stream().map(MojoExecution::getGoal).map(String::toLowerCase) .anyMatch(s -> s.contains("group.idealworld.dew:dew-maven-plugin:release") || s.contains("dew:release") || s.contains("deploy"))) { return; } DependencyContext dependencyContext = newDependencyContext(session, mojoExecutions); PhaseRecorder phaseRecorder = new PhaseRecorder(session.getCurrentProject()); for (MojoExecution mojoExecution : mojoExecutions) { execute(session, mojoExecution, projectIndex, dependencyContext, phaseRecorder); } }
Example #23
Source File: SystemPropertyRepositoryLoaderTest.java From yaks with Apache License 2.0 | 5 votes |
@Test public void shouldLoadFromSystemProperties() throws LifecycleExecutionException { System.setProperty(ExtensionSettings.REPOSITORIES_SETTING_KEY, "central=https://repo.maven.apache.org/maven2/,jboss-ea=https://repository.jboss.org/nexus/content/groups/ea/"); List<Repository> repositoryList = loader.load(logger); TestHelper.verifyRepositories(repositoryList); }
Example #24
Source File: CompatibilityTestMojo.java From java-specialagent with Apache License 2.0 | 5 votes |
private void assertCompatibility(final List<CompatibilitySpec> compatibilitySpecs, final boolean shouldPass) throws DependencyResolutionException, IOException, LifecycleExecutionException, MojoExecutionException, InvalidVersionSpecificationException { getLog().info("Running " + (shouldPass ? "PASS" : "FAIL") + " compatibility tests..."); for (final CompatibilitySpec compatibilitySpec : compatibilitySpecs) { String versionSpec = null; int numSpecs = -1; final int size = compatibilitySpec.getDependencies().size(); final List<Dependency>[] resolvedVersions = new List[size]; for (int i = 0; i < size; ++i) { final ResolvableDependency dependency = compatibilitySpec.getDependencies().get(i); final boolean isSingleVersion = dependency.isSingleVersion(); if (!isSingleVersion) { if (versionSpec == null) versionSpec = dependency.getVersion(); else if (!versionSpec.equals(dependency.getVersion())) throw new MojoExecutionException("Version across all dependencies in a <pass> or <fail> spec must be equal"); } resolvedVersions[i] = dependency.resolveVersions(getProject(), getLog()); if (!isSingleVersion) { if (numSpecs == -1) numSpecs = resolvedVersions[i].size(); else if (numSpecs != resolvedVersions[i].size()) throw new MojoExecutionException("Expeted the same number of resolved versions for: " + compatibilitySpec); } } if (numSpecs == -1) numSpecs = 1; for (int i = 0; i < numSpecs; ++i) { final Dependency[] dependencies = new Dependency[resolvedVersions.length]; for (int j = 0; j < resolvedVersions.length; ++j) dependencies[j] = resolvedVersions[j].get(resolvedVersions[j].size() == numSpecs ? i : 0); assertCompatibility(dependencies, shouldPass); } } }
Example #25
Source File: DisplayPluginUpdatesMojo.java From versions-maven-plugin with Apache License 2.0 | 5 votes |
/** * Find optional mojos for lifecycle. * * @param project the project * @param lifecycle the lifecycle * @return the list * @throws LifecycleExecutionException the lifecycle execution exception * @throws PluginNotFoundException the plugin not found exception */ private List<String> findOptionalMojosForLifecycle( MavenProject project, Lifecycle lifecycle ) throws LifecycleExecutionException, PluginNotFoundException { String packaging = project.getPackaging(); List<String> optionalMojos = null; LifecycleMapping m = (LifecycleMapping) findExtension( project, LifecycleMapping.ROLE, packaging, session.getSettings(), session.getLocalRepository() ); if ( m != null ) { optionalMojos = m.getOptionalMojos( lifecycle.getId() ); } if ( optionalMojos == null ) { try { m = (LifecycleMapping) session.lookup( LifecycleMapping.ROLE, packaging ); optionalMojos = m.getOptionalMojos( lifecycle.getId() ); } catch ( ComponentLookupException e ) { getLog().debug( "Error looking up lifecycle mapping to retrieve optional mojos. Lifecycle ID: " + lifecycle.getId() + ". Error: " + e.getMessage(), e ); } } if ( optionalMojos == null ) { optionalMojos = Collections.emptyList(); } return optionalMojos; }
Example #26
Source File: FingerprintMojo.java From java-specialagent with Apache License 2.0 | 5 votes |
@Override public void execute() throws MojoExecutionException, MojoFailureException { if (isRunning) return; isRunning = true; if (isSkip()) { getLog().info("Skipping plugin execution"); return; } if ("pom".equalsIgnoreCase(getProject().getPackaging())) { getLog().info("Skipping for \"pom\" module."); return; } try { for (final Artifact artifact : getProject().getDependencyArtifacts()) { if ("io.opentracing".equals(artifact.getGroupId()) && "opentracing-api".equals(artifact.getArtifactId())) { apiVersion = artifact.getVersion(); break; } } createDependenciesTgf(); createFingerprintBin(); createLocalRepoFile(); createPluginName(); } catch (final DependencyResolutionException | IOException | LifecycleExecutionException e) { throw new MojoFailureException(e.getMessage(), e); } finally { isRunning = false; } }
Example #27
Source File: SystemPropertyDependencyLoaderTest.java From yaks with Apache License 2.0 | 5 votes |
@Test public void shouldLoadFromSystemPropertiesWithVersionResolving() throws LifecycleExecutionException, URISyntaxException { System.setProperty(ExtensionSettings.DEPENDENCIES_SETTING_KEY, "org.foo:foo-artifact:@foo.version@,org.bar:bar-artifact:@bar.version@"); properties.put("foo.version", "1.0.0"); properties.put("bar.version", "1.5.0"); List<Dependency> dependencyList = loader.load(properties, logger); TestHelper.verifyDependencies(dependencyList); }
Example #28
Source File: SystemPropertyDependencyLoaderTest.java From yaks with Apache License 2.0 | 5 votes |
@Test public void shouldLoadFromSystemProperties() throws LifecycleExecutionException, URISyntaxException { System.setProperty(ExtensionSettings.DEPENDENCIES_SETTING_KEY, "org.foo:foo-artifact:1.0.0,org.bar:bar-artifact:1.5.0"); List<Dependency> dependencyList = loader.load(properties, logger); TestHelper.verifyDependencies(dependencyList); }
Example #29
Source File: FingerprintMojo.java From java-specialagent with Apache License 2.0 | 5 votes |
private void createDependenciesTgf() throws DependencyResolutionException, IOException, LifecycleExecutionException, MojoExecutionException, MojoFailureException { final File file = new File(getProject().getBuild().getOutputDirectory(), "dependencies.tgf"); getLog().info("--> dependencies.tgf <--"); HackMojo.setField(TreeMojo.class, this, "outputType", "tgf"); HackMojo.setField(TreeMojo.class, this, "outputFile", file); super.execute(); if (isolatedDependencies == null || isolatedDependencies.size() == 0) return; try (final RandomAccessFile raf = new RandomAccessFile(file, "rw")) { for (String line; (line = raf.readLine()) != null;) { if ("#".equals(line)) { raf.seek(raf.getFilePointer() - 3); for (final IsolatedDependency isolatedDependency : isolatedDependencies) { if (isolatedDependency.getVersion() != null) throw new MojoExecutionException("Version of " + isolatedDependency + " must be specified in <dependencyManagement>"); isolatedDependency.setVersion(MavenUtil.lookupVersion(getProject(), isolatedDependency)); raf.write(("\n0 " + isolatedDependency.getGroupId() + ":" + isolatedDependency.getArtifactId() + ":jar:" + isolatedDependency.getVersion() + ":isolated").getBytes()); } raf.write("\n#".getBytes()); raf.setLength(raf.getFilePointer()); final Dependency[] rollback = MutableMojo.replaceDependencies(getProject().getDependencies(), MavenDependency.toDependencies(isolatedDependencies)); MutableMojo.resolveDependencies(getSession(), execution, executor, projectDependenciesResolver); MutableMojo.rollbackDependencies(getProject().getDependencies(), rollback); MutableMojo.resolveDependencies(getSession(), execution, executor, projectDependenciesResolver); return; } } } throw new MojoExecutionException("Could not write isolated dependencies into dependencies.tgf"); }
Example #30
Source File: ProjectModelEnricher.java From yaks with Apache License 2.0 | 5 votes |
/** * Dynamically add project dependencies based on different configuration sources such as environment variables, * system properties configuration files. * @param projectModel * @throws LifecycleExecutionException */ private void injectProjectDependencies(Model projectModel) throws LifecycleExecutionException { logger.info("Add dynamic project dependencies ..."); List<Dependency> dependencyList = projectModel.getDependencies(); dependencyList.addAll(new FileBasedDependencyLoader().load(projectModel.getProperties(), logger)); dependencyList.addAll(new SystemPropertyDependencyLoader().load(projectModel.getProperties(), logger)); dependencyList.addAll(new EnvironmentSettingDependencyLoader().load(projectModel.getProperties(), logger)); dependencyList.addAll(new FeatureTagsDependencyLoader().load(projectModel.getProperties(), logger)); }