List of usage examples for org.apache.maven.project MavenProject getModel
public Model getModel()
From source file:com.simpligility.maven.plugins.android.phase_prebuild.ClasspathModifierLifecycleParticipant.java
License:Open Source License
/** * Add jar files in libs into the project classpath. *///from w ww . java 2s . c o m private void addLibsJarsToClassPath(UnpackedLibHelper helper, MavenProject project, Artifact artifact) throws MavenExecutionException { try { final File unpackLibFolder = helper.getUnpackedLibFolder(artifact); final File artifactFile = helper.getArtifactToFile(artifact); ZipFile zipFile = new ZipFile(artifactFile); Enumeration enumeration = zipFile.entries(); while (enumeration.hasMoreElements()) { ZipEntry entry = (ZipEntry) enumeration.nextElement(); String entryName = entry.getName(); // Only jar files under 'libs' directory to be processed. if (Pattern.matches("^libs/.+\\.jar$", entryName)) { final File libsJarFile = new File(unpackLibFolder, entryName); log.warn("Adding jar from libs folder to classpath: " + libsJarFile); // In order to satisfy the LifecycleDependencyResolver on execution up to a phase that // has a Mojo requiring dependency resolution I need to create a dummy classesJar here. if (!libsJarFile.getParentFile().exists()) { libsJarFile.getParentFile().mkdirs(); } libsJarFile.createNewFile(); // Add the jar to the classpath. final Dependency dependency = createSystemScopeDependency(artifact, libsJarFile, libsJarFile.getName()); project.getModel().addDependency(dependency); addedJarFromLibs = true; } } } catch (MojoExecutionException e) { log.debug("Error extract jars"); } catch (ZipException e) { log.debug("Error"); } catch (IOException e) { log.debug("Error"); } }
From source file:com.simpligility.maven.plugins.android.phase_prebuild.ClasspathModifierLifecycleParticipant.java
License:Open Source License
/** * Add the dependent library classes to the project classpath. *//*from w w w. jav a2 s . c om*/ private void addClassesToClasspath(UnpackedLibHelper helper, MavenProject project, Artifact artifact) throws MavenExecutionException { // Work out where the dep will be extracted and calculate the file path to the classes jar. // This is location where the GenerateSourcesMojo will extract the classes. final File classesJar = helper.getUnpackedClassesJar(artifact); log.debug("Adding to classpath : " + classesJar); // In order to satisfy the LifecycleDependencyResolver on execution up to a phase that // has a Mojo requiring dependency resolution I need to create a dummy classesJar here. classesJar.getParentFile().mkdirs(); try { final ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(classesJar)); zipOutputStream.putNextEntry(new ZipEntry("dummy")); zipOutputStream.close(); log.debug("Created dummy " + classesJar.getName() + " exist=" + classesJar.exists()); } catch (IOException e) { throw new MavenExecutionException("Could not add " + classesJar.getName() + " as dependency", e); } // Modify the classpath to use an extracted dex file. This will overwrite // any exisiting dependencies with the same information. final Dependency dependency = createSystemScopeDependency(artifact, classesJar, null); final Dependency providedJar = findProvidedDependencies(dependency, project); if (providedJar != null) { project.getModel().removeDependency(providedJar); } project.getModel().addDependency(dependency); }
From source file:com.xpn.xwiki.tool.backup.AbstractImportMojo.java
License:Open Source License
protected void installExtension(Artifact artifact, ComponentManager componentManager, String namespace) throws ComponentLookupException, InstallException, LocalExtensionRepositoryException, MojoExecutionException {/*from ww w. ja va 2 s .c o m*/ // We need to distinguish between extensions installed explicitly and their transitive dependencies. // We have to create our own Set because Maven changes the fields from the dependency Artifacts (e.g. resolves // their version) after they are added to the Set of dependencies and this causes the hash code to change. As a // result the #contains(Artifact) method doesn't work as expected because it uses the new hash code. Set<Artifact> directDependencies = new HashSet<>(this.project.getDependencyArtifacts()); LocalExtensionRepository localExtensionRepository = componentManager .getInstance(LocalExtensionRepository.class); InstalledExtensionRepository installedExtensionRepository = componentManager .getInstance(InstalledExtensionRepository.class); MavenProject dependencyProject = getMavenProject(artifact); ConverterManager converter = componentManager.getInstance(ConverterManager.class); Extension mavenExtension = converter.convert(Extension.class, dependencyProject.getModel()); DefaultLocalExtension extension = new DefaultLocalExtension(null, mavenExtension); extension.setFile(artifact.getFile()); LocalExtension localExtension = localExtensionRepository.storeExtension(extension); installedExtensionRepository.installExtension(localExtension, namespace, !directDependencies.contains(artifact), Collections.<String, Object>singletonMap("user.reference", this.installUser)); getLog().info(" ... Registered extension [" + extension + "]"); }
From source file:com.xwikisas.xcs.tools.dependenciespackager.PackageExtensionsMojo.java
License:Open Source License
private void installArtifact(Artifact artifact) throws MojoExecutionException, ComponentLookupException, LocalExtensionRepositoryException { MavenProject project = getMavenProject(artifact); // Convert the current artifact to an XWiki Extension DefaultLocalExtension extension = new DefaultLocalExtension(null, new ExtensionId(artifact.getGroupId() + ':' + artifact.getArtifactId(), artifact.getBaseVersion()), artifact.getType());//from w w w. j ava2 s . c o m toExtension(extension, project.getModel()); extension.setFile(artifact.getFile()); // Install the extension getLog().info(String.format("Copying dependency [%s:%s, %s].", artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion())); localExtensionRepository.storeExtension(extension); }
From source file:de.eacg.ecs.plugin.ComponentId.java
public static ComponentId create(MavenProject project) { return create(project.getModel()); }
From source file:de.jiac.micro.mojo.ConfiguratorMojo.java
License:Open Source License
private Model checkModel(Model model) throws ModelInterpolationException, ProjectBuildingException { if (model.getParent() != null) { Parent parent = model.getParent(); Artifact parentArt = artifactFactory.createArtifact(parent.getGroupId(), parent.getArtifactId(), parent.getVersion(), "compile", "pom"); MavenProject parentProj = mavenProjectBuilder.buildFromRepository(parentArt, remoteRepositories, localRepository);/*from w w w . ja v a 2 s . c o m*/ Model parentModel = parentProj.getModel(); if (parentModel.getParent() != null) { parentModel = checkModel(parentModel); } modelInheritanceAssembler.assembleModelInheritance(model, parentModel); } DefaultProjectBuilderConfiguration projectBuilderConfig = new DefaultProjectBuilderConfiguration(); projectBuilderConfig.setExecutionProperties(model.getProperties()); return modelInterpolator.interpolate(model, null, projectBuilderConfig, true); }
From source file:de.smartics.maven.enforcer.rule.NoSnapshotsInDependencyManagementRule.java
License:Apache License
/** * {@inheritDoc}// w w w. j a v a 2s. c om */ public void execute(final EnforcerRuleHelper helper) throws EnforcerRuleException { final Log log = helper.getLog(); try { final MavenProject project = (MavenProject) helper.evaluate("${project}"); final boolean isSnapshot = project.getArtifact().isSnapshot(); if (onlyWhenRelease && isSnapshot) { log.info(getCacheId() + ": Skipping since not a release."); return; } final DependencyManagement dependencyManagement = project.getModel().getDependencyManagement(); if (dependencyManagement == null) { log.debug(getCacheId() + ": No dependency management block found."); return; } if (!checkOnlyResolvedDependencies) { final DependencyManagement originalDependencyManagement = project.getOriginalModel() .getDependencyManagement(); if (originalDependencyManagement != null) { final List<Dependency> declaredDependencies = originalDependencyManagement.getDependencies(); if (declaredDependencies != null && !declaredDependencies.isEmpty()) { checkDependenciesForSnapshots(helper, log, declaredDependencies); } } } final List<Dependency> dependencies = dependencyManagement.getDependencies(); if (dependencies == null || dependencies.isEmpty()) { log.debug(getCacheId() + ": No dependencies in dependency management block found."); return; } checkDependenciesForSnapshots(helper, log, dependencies); } catch (final ExpressionEvaluationException e) { throw new EnforcerRuleException("Unable to evaluate expression '" + e.getLocalizedMessage() + "'.", e); } }
From source file:fr.fastconnect.factory.tibco.bw.maven.AbstractBWMojo.java
License:Apache License
public boolean propertyExists(MavenProject mavenProject, String propertyName) { return mavenProject.getOriginalModel().getProperties().containsKey(propertyName) || mavenProject.getModel().getProperties().containsKey(propertyName) || session.getRequest().getUserProperties().containsKey(propertyName) || propertyExistsInSettings(propertyName, session.getSettings()); }
From source file:fr.fastconnect.factory.tibco.bw.maven.AbstractBWMojo.java
License:Apache License
public String getPropertyValue(MavenProject mavenProject, String propertyName, boolean lookInSettingsProperties, boolean lookInCommandLine, boolean onlyInOriginalModel) { if (mavenProject == null) return null; String result = null;/*from w w w . ja va 2 s. c o m*/ if (onlyInOriginalModel) { result = mavenProject.getOriginalModel().getProperties().getProperty(propertyName); } else { result = mavenProject.getModel().getProperties().getProperty(propertyName); } if (lookInCommandLine && (result == null || result.isEmpty())) { result = getPropertyValueInCommandLine(propertyName, session); } if (lookInSettingsProperties && (result == null || result.isEmpty())) { result = getPropertyValueInSettings(propertyName, settings); } return result; }
From source file:fr.fastconnect.factory.tibco.bw.maven.BWLifecycleParticipant.java
License:Apache License
private List<String> activateProfilesWithProperties(MavenProject mavenProject, List<String> activeProfileIds) { if (mavenProject == null) return activeProfileIds; List<String> result = new ArrayList<String>(); if (activeProfileIds != null) { result.addAll(activeProfileIds); }/*from w ww . java 2 s . c o m*/ for (Profile profile : mavenProject.getModel().getProfiles()) { Activation activation = profile.getActivation(); if (activation != null) { ActivationProperty property = activation.getProperty(); if (property != null) { String name = property.getName(); if (name != null) { String value; if (name.startsWith("!")) { value = propertiesManager.getPropertyValue(name.substring(1)); } else { value = propertiesManager.getPropertyValue(name); } if (value != null) { if (!name.startsWith("!") && value.equals(property.getValue()) || name.startsWith("!") && !value.equals(property.getValue())) { result.add(profile.getId()); } } } } } } return result; }