List of usage examples for org.apache.maven.project MavenProject getArtifactId
public String getArtifactId()
From source file:org.wso2.developerstudio.eclipse.utils.jdt.JavaLibraryUtil.java
License:Open Source License
/** * This method is extracting the jar libraries from the Eclipse java project * classpath and retrieve maven based information from them. * //ww w .ja v a2 s . c o m * @param project * @return Map of classpath entreis and their maven information. If the * value is null for an entry, then that java library does not * contain any maven project information. * @throws Exception */ public static Map<String, JavaLibraryBean> getDependencyInfoMap(IProject project) throws Exception { HashMap<String, JavaLibraryBean> dependencyInfoMap = new HashMap<String, JavaLibraryBean>(); List<IPackageFragmentRoot> fullList = new ArrayList<IPackageFragmentRoot>(); fullList.addAll(Arrays.asList(JavaUtils.getReferencedLibrariesForProject(project))); fullList.addAll(Arrays.asList(JavaUtils.getReferencedVariableLibrariesForProject(project))); ArchiveManipulator archiver = new ArchiveManipulator(); IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); Map<QualifiedName, String> persistentProperties = workspaceRoot.getPersistentProperties(); Map<QualifiedName, Object> sessionProperties = workspaceRoot.getSessionProperties(); ITemporaryFileTag createNewTempTag = FileUtils.createNewTempTag(); for (int i = 0; i < fullList.size(); i++) { String libraryFile = null; if (fullList.get(i).getPath().toFile().exists()) { libraryFile = fullList.get(i).getPath().toOSString(); } else { libraryFile = fullList.get(i).getResource().getLocation().toOSString(); } String persistentProperty = persistentProperties.get(new QualifiedName("", libraryFile)); if (persistentProperty == null) { File tempLocation = FileUtils.createTempDirectory(); File tempFile = new File(tempLocation, fullList.get(i).getElementName()); FileUtils.copy(new File(libraryFile), tempFile); File extractLocation = new File(tempLocation, "temp_" + tempFile.getName()); archiver.extract(tempFile, extractLocation); // If this is maven generated, we cna get the info from pom file boolean isMavenBuild = true; File[] pomFiles = FileUtils.getAllMatchingFiles( extractLocation.getPath() + File.separator + "META-INF", POM_FILE_NAME, POM_FILE_EXTENSION, new ArrayList<File>()); if (pomFiles == null) { // Not used maven to build isMavenBuild = false; } else if (pomFiles.length > 1) { // This is impossible. Hence corrupted. Do something. } else if (pomFiles.length == 1) { File pomFile = pomFiles[0]; MavenProject mavenProject = getMavenProject(pomFile); // JavaLibraryBean bean = new // JavaLibraryBean("/media/dev/wso2products/3.2.0/wso2greg-3.7.0/lib", // "org.wso2.sample", "test.sample", "1.0.0"); JavaLibraryBean bean = new JavaLibraryBean(libraryFile, mavenProject.getGroupId(), mavenProject.getArtifactId(), mavenProject.getVersion()); if (isProperty(bean.toString())) { resolveBeanProperties(mavenProject, bean); } workspaceRoot.setPersistentProperty(new QualifiedName("", libraryFile), bean.getGroupId() + ":" + bean.getArtifactId() + ":" + bean.getVersion()); workspaceRoot.setSessionProperty(new QualifiedName("", libraryFile), bean); dependencyInfoMap.put(fullList.get(i).getElementName(), bean); } if (!isMavenBuild) { // Set null as the bean. Then the client will be prompt to // enter // the maven details for the lib. dependencyInfoMap.put(fullList.get(i).getElementName(), null); } // FileUtils.deleteDir(tempLocation); FileUtils.deleteDirectories(tempLocation); } else { // if we have the persistent property Object sessionProperty = sessionProperties.get(new QualifiedName("", libraryFile)); if (sessionProperty != null) { dependencyInfoMap.put(fullList.get(i).getElementName(), (JavaLibraryBean) sessionProperty); } else { String[] mavenInfo = persistentProperty.split(":"); JavaLibraryBean bean = new JavaLibraryBean(libraryFile, mavenInfo[0], mavenInfo[1], mavenInfo[2]); workspaceRoot.setSessionProperty(new QualifiedName("", libraryFile), bean); dependencyInfoMap.put(fullList.get(i).getElementName(), bean); } } } createNewTempTag.clearAndEnd(); return (Map<String, JavaLibraryBean>) Collections.unmodifiableMap(dependencyInfoMap); }
From source file:org.wso2.maven.capp.model.CAppArtifactDependency.java
License:Open Source License
private Dependency createMavenDependency() { Dependency mavenDependency = new Dependency(); MavenProject project = cAppArtifact.getProject(); mavenDependency.setGroupId(project.getGroupId()); mavenDependency.setArtifactId(project.getArtifactId()); mavenDependency.setVersion(project.getVersion()); mavenDependency.setScope(CAppMavenUtils.CAPP_SCOPE_PREFIX); return mavenDependency; }
From source file:org.wso2.maven.dashboards.FileManagementUtils.java
License:Open Source License
public static void processMavenProject(File project, String artifactType, MavenProject mavenProject, File path) throws MojoExecutionException { try {/*from w w w . ja v a 2 s .com*/ String artifactName = mavenProject.getArtifactId() + SEPERATOR + mavenProject.getVersion() + FILE_TYPE_SEPERATOR + artifactType; File archive = createArchive(path, project, artifactName); if (archive != null && archive.exists()) { mavenProject.getArtifact().setFile(archive); } } catch (IOException e) { throw new MojoExecutionException("Error while creating gadget archive " + mavenProject.getArtifactId() + FILE_TYPE_SEPERATOR + artifactType, e); } }
From source file:org.wso2.maven.MavenReleasePrePrepareMojo.java
License:Open Source License
/** * set Registry artifact version in artifact.xml file * /* w w w. j ava2s .c o m*/ * @param prop * properties in release.properties file * @param repoType * type of the repository * @param artifactXml * @throws FactoryConfigurationError * @throws Exception */ private void setRegArtifactVersion(Properties prop, String repoType, File artifactXml) throws FactoryConfigurationError, Exception { File pomFile = new File(artifactXml.getParent() + File.separator + POM_XML); MavenProject mavenProject = getMavenProject(pomFile); String releaseVersion = prop.getProperty( PROJECT + repoType + "." + mavenProject.getGroupId() + ":" + mavenProject.getArtifactId()); GeneralProjectArtifact projectArtifact = new GeneralProjectArtifact(); projectArtifact.fromFile(artifactXml); for (RegistryArtifact artifact : projectArtifact.getAllESBArtifacts()) { if (artifact.getVersion() != null && artifact.getType() != null) { if (releaseVersion != null) { artifact.setVersion(releaseVersion); } } } projectArtifact.toFile(); }
From source file:org.wso2.maven.MavenReleasePrePrepareMojo.java
License:Open Source License
/** * set ESB artifact version in artifact.xml file * /*from w w w. j a v a 2 s .co m*/ * @param prop * properties in release.properties file * @param repoType * type of the repository * @param artifactXml * @throws FactoryConfigurationError * @throws Exception */ private void setESBArtifactVersion(Properties prop, String repoType, File artifactXml) throws FactoryConfigurationError, Exception { File pomFile = new File(artifactXml.getParent() + File.separator + POM_XML); MavenProject mavenProject = getMavenProject(pomFile); String releaseVersion = prop.getProperty( PROJECT + repoType + "." + mavenProject.getGroupId() + ":" + mavenProject.getArtifactId()); ESBProjectArtifact projectArtifact = new ESBProjectArtifact(); projectArtifact.fromFile(artifactXml); for (ESBArtifact artifact : projectArtifact.getAllESBArtifacts()) { if (artifact.getVersion() != null && artifact.getType() != null) { if (releaseVersion != null) { artifact.setVersion(releaseVersion); } } } projectArtifact.toFile(); }
From source file:org.wso2.maven.pckg.prepare.PackagePrepareDefaultScopeMojo.java
License:Open Source License
private void filterAllCappProjects(List<MavenProject> mavenProjects) { cappMavenProjects = new ArrayList<>(); for (MavenProject mavenProject : mavenProjects) { String packaging = mavenProject.getPackaging(); if (packaging != null && packaging.equals(MavenConstants.CAPP_PACKAGING)) { if (isDebugEnabled) { log.debug("Identified the composite application project: " + mavenProject.getGroupId() + ":" + mavenProject.getArtifactId() + ":" + mavenProject.getVersion()); }//from w w w .ja va 2s . co m cappMavenProjects.add(mavenProject); } } }
From source file:org.wso2.maven.pckg.prepare.PackagePrepareSystemScopeMojo.java
License:Open Source License
private void aggregateDependencies(List<MavenProject> mavenProjects) { dependencySystemPathMap = new HashMap<>(); for (MavenProject mavenProject : mavenProjects) { String packaging = mavenProject.getPackaging(); // CAPP projects are ignored. if (packaging == null || !MavenConstants.CAPP_PACKAGING.equals(packaging)) { try { dependencySystemPathMap.putAll(PackagePrepareUtils.getArtifactsSystemPathMap(mavenProject)); } catch (FactoryConfigurationError | Exception e) { // Can proceed even if this is reached log.warn("Failed to retrieve dependencies from project: " + mavenProject.getGroupId() + ":" + mavenProject.getArtifactId() + ":" + mavenProject.getVersion(), e); }/* w w w. j a va2 s . c o m*/ } } if (isDebugEnabled) { Iterator<Entry<String, String>> dependencyIterator = dependencySystemPathMap.entrySet().iterator(); while (dependencyIterator.hasNext()) { log.debug("Identified system path of: " + dependencyIterator.next().getKey()); } } }
From source file:org.wso2.maven.plugin.carbonui.CarbonUIPOMGenMojo.java
License:Open Source License
protected void addPlugins(MavenProject artifactMavenProject, Artifact artifact) { Plugin pluginAxis2 = CAppMavenUtils.createPluginEntry(artifactMavenProject, "org.wso2.maven", "maven-carbon-ui-plugin", WSO2MavenPluginConstantants.MAVEN_CARBON_UI_PLUGIN_VERSION, true); // PluginExecution executionAxis2 = new PluginExecution(); // executionAxis2.setId("package-war"); // executionAxis2.setPhase("package"); // List goalsAxis2 = new ArrayList<String>(); // goalsAxis2.add("package-war"); // executionAxis2.setGoals(goalsAxis2); // pluginAxis2.addExecution(executionAxis2); Xpp3Dom config = (Xpp3Dom) pluginAxis2.getConfiguration(); Xpp3Dom artifactItems = CAppMavenUtils.createConfigurationNode(config, "artifact"); String relativePath = org.wso2.developerstudio.eclipse.utils.file.FileUtils.getRelativePath( new File(artifact.getFile().getParentFile().getParentFile().getParentFile().getParentFile() .getParentFile().getPath() + File.separator + "target" + File.separator + "capp" + File.separator + "artifacts" + File.separator + artifactMavenProject.getArtifactId()), artifact.getFile());//from w w w . j a v a 2 s. c o m artifactItems.setValue(relativePath); }
From source file:org.wso2.maven.PrepareReleasedArtifactsMojo.java
License:Open Source License
@Override protected String getNewVersion(File artifactXml) throws IOException, XmlPullParserException { File pomFile = new File(artifactXml.getParent() + File.separator + POM_XML); MavenProject mavenProject = getMavenProject(pomFile); String newVersion = releaseProperties.getProperty( PROJECT_PREFIX + REL + "." + mavenProject.getGroupId() + ":" + mavenProject.getArtifactId()); return newVersion; }
From source file:org.wso2.maven.PrepareSnapshotArtifactsMojo.java
License:Open Source License
@Override protected String getNewVersion(File artifactXml) throws IOException, XmlPullParserException { File pomFile = new File(artifactXml.getParent() + File.separator + POM_XML); MavenProject mavenProject = getMavenProject(pomFile); String newVersion = releaseProperties.getProperty( PROJECT_PREFIX + DEV + "." + mavenProject.getGroupId() + ":" + mavenProject.getArtifactId()); return newVersion; }