Search in sources :

Example 31 with DefaultArtifactVersion

use of org.apache.maven.artifact.versioning.DefaultArtifactVersion in project maven-plugins by apache.

the class AbstractJavadocMojo method populateCompileArtifactMap.

/**
 * Method to put the artifacts in the hashmap.
 *
 * @param compileArtifactMap the hashmap that will contain the artifacts
 * @param artifactList       the list of artifacts that will be put in the map
 * @throws MavenReportException if any
 */
private void populateCompileArtifactMap(Map<String, Artifact> compileArtifactMap, Collection<Artifact> artifactList) throws MavenReportException {
    if (artifactList == null) {
        return;
    }
    for (Artifact newArtifact : artifactList) {
        File file = newArtifact.getFile();
        if (file == null) {
            throw new MavenReportException("Error in plugin descriptor - " + "dependency was not resolved for artifact: " + newArtifact.getGroupId() + ":" + newArtifact.getArtifactId() + ":" + newArtifact.getVersion());
        }
        if (compileArtifactMap.get(newArtifact.getDependencyConflictId()) != null) {
            Artifact oldArtifact = compileArtifactMap.get(newArtifact.getDependencyConflictId());
            ArtifactVersion oldVersion = new DefaultArtifactVersion(oldArtifact.getVersion());
            ArtifactVersion newVersion = new DefaultArtifactVersion(newArtifact.getVersion());
            if (newVersion.compareTo(oldVersion) > 0) {
                compileArtifactMap.put(newArtifact.getDependencyConflictId(), newArtifact);
            }
        } else {
            compileArtifactMap.put(newArtifact.getDependencyConflictId(), newArtifact);
        }
    }
}
Also used : DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) ArtifactVersion(org.apache.maven.artifact.versioning.ArtifactVersion) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) File(java.io.File) BootclasspathArtifact(org.apache.maven.plugins.javadoc.options.BootclasspathArtifact) JavadocPathArtifact(org.apache.maven.plugins.javadoc.options.JavadocPathArtifact) ResourcesArtifact(org.apache.maven.plugins.javadoc.options.ResourcesArtifact) Artifact(org.apache.maven.artifact.Artifact) TagletArtifact(org.apache.maven.plugins.javadoc.options.TagletArtifact) DocletArtifact(org.apache.maven.plugins.javadoc.options.DocletArtifact) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 32 with DefaultArtifactVersion

use of org.apache.maven.artifact.versioning.DefaultArtifactVersion in project jangaroo-tools by CoreMedia.

the class ExmlToMxmlMojo method execute.

@Override
public void execute() throws MojoExecutionException {
    boolean useNewPackagingType = extAsVersion != null && new DefaultArtifactVersion(extAsVersion).compareTo(EXT_AS_FIRST_SWC_ARTIFACT_VERSION) >= 0;
    if (!renameOnly && (hasExmlConfiguration() || "jangaroo".equals(getProject().getPackaging()))) {
        getLog().info("reading POM from " + getProject().getBasedir().getPath());
        PomConverter pomConverter = new PomConverter(getProject().getBasedir());
        getLog().info("removing exml-maven-plugin from POM");
        pomConverter.removeExmlPlugin();
        String newPackaging = useNewPackagingType ? "swc" : "jangaroo-pkg";
        getLog().info("changing packaging from 'jangaroo' to '" + newPackaging + "'");
        pomConverter.changePackaging(newPackaging);
        if (useNewPackagingType) {
            getLog().info("adding dependency type 'swc' to all compile dependencies");
            pomConverter.addDependencyType(newPackaging);
        }
        getLog().info("updating POM at " + getProject().getBasedir().getPath());
        pomConverter.writePom();
    }
    if (!isExmlProject()) {
        getLog().info("not an EXML project, skipping MXML conversion");
        return;
    }
    if (renameOnly) {
        getLog().info("Renaming EXML files to MXML files");
        try {
            renameFiles(getSourceDirectory(), "exml", "mxml");
            renameFiles(getTestSourceDirectory(), "exml", "mxml");
        } catch (IOException e) {
            throw new MojoExecutionException("error while renaming EXML files", e);
        }
        return;
    }
    if (alreadyRenamed) {
        getLog().info("Renaming MXML files back to EXML files before running the conversion");
        try {
            renameFiles(getSourceDirectory(), "mxml", "exml");
            renameFiles(getTestSourceDirectory(), "mxml", "exml");
        } catch (IOException e) {
            throw new MojoExecutionException("error while renaming files", e);
        }
    }
    if (extAsVersion == null) {
        throw new MojoExecutionException("exml-to-mxml needs an extAsVersion.");
    }
    Artifact extAsArtifact = resolveExtAsArtifact(extAsVersion, useNewPackagingType ? "swc" : "jar");
    File extAsJar = extAsArtifact.getFile();
    // Convert main EXML sources to MXML:
    ExmlConfiguration config = createExmlConfiguration(getActionScriptClassPath(), Collections.singletonList(getSourceDirectory()), getGeneratedSourcesDirectory());
    config.setExtAsJar(extAsJar);
    new Exmlc(config).convertAllExmlToMxml();
    // Also convert test EXML sources to MXML:
    if (getTestSourceDirectory() != null && getTestSourceDirectory().exists()) {
        ExmlConfiguration testConfig = createExmlConfiguration(getActionScriptTestClassPath(), Collections.singletonList(getTestSourceDirectory()), getGeneratedTestSourcesDirectory());
        testConfig.setExtAsJar(extAsJar);
        new Exmlc(testConfig).convertAllExmlToMxml();
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Exmlc(net.jangaroo.exml.compiler.Exmlc) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) IOException(java.io.IOException) ExmlConfiguration(net.jangaroo.exml.config.ExmlConfiguration) FileUtils.moveFile(org.apache.commons.io.FileUtils.moveFile) File(java.io.File) PomConverter(net.jangaroo.exml.mojo.pom.PomConverter) Artifact(org.apache.maven.artifact.Artifact)

Example 33 with DefaultArtifactVersion

use of org.apache.maven.artifact.versioning.DefaultArtifactVersion in project project-build-plugin by axonivy.

the class URLEngineDownloader method findEngineDownloadUrl.

public URL findEngineDownloadUrl(InputStream htmlStream) throws MojoExecutionException, MalformedURLException {
    String engineFileNameRegex = "AxonIvyEngine[^.]+?\\.[^.]+?\\.+[^_]*?_" + osArchitecture + "\\.zip";
    Pattern enginePattern = Pattern.compile("href=[\"|'][^\"']*?" + engineFileNameRegex + "[\"|']");
    try (Scanner scanner = new Scanner(htmlStream)) {
        String engineLink = null;
        while (StringUtils.isBlank(engineLink)) {
            String engineLinkMatch = scanner.findWithinHorizon(enginePattern, 0);
            if (engineLinkMatch == null) {
                throw new MojoExecutionException("Could not find a link to engine for version '" + ivyVersion + "' on site '" + engineListPageUrl + "'");
            }
            String versionString = StringUtils.substringBetween(engineLinkMatch, "AxonIvyEngine", "_" + osArchitecture);
            ArtifactVersion version = new DefaultArtifactVersion(EngineVersionEvaluator.toReleaseVersion(versionString));
            if (ivyVersionRange.containsVersion(version)) {
                engineLink = StringUtils.replace(engineLinkMatch, "\"", "'");
                engineLink = StringUtils.substringBetween(engineLink, "href='", "'");
            }
        }
        return toAbsoluteLink(engineListPageUrl, engineLink);
    }
}
Also used : Pattern(java.util.regex.Pattern) Scanner(java.util.Scanner) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) ArtifactVersion(org.apache.maven.artifact.versioning.ArtifactVersion) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion)

Example 34 with DefaultArtifactVersion

use of org.apache.maven.artifact.versioning.DefaultArtifactVersion in project project-build-plugin by axonivy.

the class BaseEngineProjectMojoTest method getNextMajor.

private static String getNextMajor(String version) {
    DefaultArtifactVersion parsed = new DefaultArtifactVersion(version);
    int majorVersion = parsed.getMajorVersion();
    String nextMajor = new StringBuilder().append(majorVersion + 1).append('.').append(parsed.getMinorVersion()).append('.').append(parsed.getIncrementalVersion()).toString();
    return nextMajor;
}
Also used : DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion)

Example 35 with DefaultArtifactVersion

use of org.apache.maven.artifact.versioning.DefaultArtifactVersion in project irontest by zheng-wang.

the class UpgradeCommand method run.

@Override
public void run() {
    SystemDatabaseYml systemDBConfiguration;
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    try {
        ConfigYml configYml = mapper.readValue(new File(ironTestHome, "config.yml"), ConfigYml.class);
        systemDBConfiguration = configYml.getSystemDatabase();
    } catch (IOException e) {
        throw new RuntimeException("Failed to read config.yml under " + ironTestHome, e);
    }
    String fullyQualifiedSystemDBURL = getFullyQualifiedSystemDBURL(ironTestHome, systemDBConfiguration.getUrl());
    DefaultArtifactVersion systemDBVersion = getSystemDBVersionStr(fullyQualifiedSystemDBURL, systemDBConfiguration.getUser(), systemDBConfiguration.getPassword());
    DefaultArtifactVersion jarFileVersion = new DefaultArtifactVersion(Version.VERSION);
    int comparison = systemDBVersion.compareTo(jarFileVersion);
    if ("SNAPSHOT".equals(systemDBVersion.getQualifier())) {
        System.out.println("System database version " + systemDBVersion + " is a SNAPSHOT version. Upgrade is not supported.");
    } else if ("SNAPSHOT".equals(jarFileVersion.getQualifier())) {
        System.out.println("Jar file version " + jarFileVersion + " is a SNAPSHOT version. Upgrade is not supported.");
    } else if (comparison == 0) {
        System.out.println("System database and the jar file are of the same version, so no need to upgrade.");
    } else if (comparison > 0) {
        // system database version is bigger than the jar file version
        System.out.printf(Constants.PROMPT_TEXT_WHEN_SYSTEM_DB_VERSION_IS_BIGGER_THAN_JAR_VERSION, systemDBVersion, jarFileVersion);
    } else {
        // system database version is smaller than the jar file version
        UpgradeActions upgradeActions = new UpgradeActions();
        try {
            upgradeActions.upgrade(systemDBVersion, jarFileVersion, ironTestHome, fullyQualifiedSystemDBURL, systemDBConfiguration.getUser(), systemDBConfiguration.getPassword());
        } catch (Exception e) {
            throw new RuntimeException("Failed to upgrade Iron Test under " + ironTestHome, e);
        }
    }
}
Also used : DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) IOException(java.io.IOException) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException)

Aggregations

DefaultArtifactVersion (org.apache.maven.artifact.versioning.DefaultArtifactVersion)37 ArtifactVersion (org.apache.maven.artifact.versioning.ArtifactVersion)12 File (java.io.File)8 IOException (java.io.IOException)7 Model (org.apache.maven.model.Model)5 FileNotFoundException (java.io.FileNotFoundException)4 MavenXpp3Reader (org.apache.maven.model.io.xpp3.MavenXpp3Reader)4 ArrayList (java.util.ArrayList)3 Matcher (java.util.regex.Matcher)3 Artifact (org.apache.maven.artifact.Artifact)3 SPluginBundle (org.bimserver.interfaces.objects.SPluginBundle)3 SPluginBundleVersion (org.bimserver.interfaces.objects.SPluginBundleVersion)3 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)3 ArtifactDescriptorException (org.eclipse.aether.resolution.ArtifactDescriptorException)3 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)3 FileReader (java.io.FileReader)2 InputStream (java.io.InputStream)2 Path (java.nio.file.Path)2 HashMap (java.util.HashMap)2 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)2