Search in sources :

Example 81 with Project

use of org.apache.tools.ant.Project in project ant-ivy by apache.

the class IvyTaskTest method testDefaultSettings.

@Test
public void testDefaultSettings() throws MalformedURLException {
    Project p = TestHelper.newProject();
    p.setBasedir("test/repositories");
    p.setProperty("myproperty", "myvalue");
    IvyTask task = new IvyTask() {

        public void doExecute() throws BuildException {
        }
    };
    task.setProject(p);
    Ivy ivy = task.getIvyInstance();
    assertNotNull(ivy);
    IvySettings settings = ivy.getSettings();
    assertNotNull(settings);
    assertEquals(new File("test/repositories/build/cache").getAbsoluteFile(), settings.getDefaultCache());
    // The next test doesn't always works on windows (mix C: and c: drive)
    assertEquals(new File("test/repositories/ivysettings.xml").getAbsolutePath().toUpperCase(), new File(settings.getVariables().getVariable("ivy.settings.file")).getAbsolutePath().toUpperCase());
    assertEquals(new File("test/repositories/ivysettings.xml").toURI().toURL().toExternalForm().toUpperCase(), settings.getVariables().getVariable("ivy.settings.url").toUpperCase());
    assertEquals(new File("test/repositories").getAbsolutePath().toUpperCase(), settings.getVariables().getVariable("ivy.settings.dir").toUpperCase());
    assertEquals("myvalue", settings.getVariables().getVariable("myproperty"));
}
Also used : Project(org.apache.tools.ant.Project) IvySettings(org.apache.ivy.core.settings.IvySettings) Ivy(org.apache.ivy.Ivy) File(java.io.File) Test(org.junit.Test)

Example 82 with Project

use of org.apache.tools.ant.Project in project revapi by revapi.

the class FileArchive method scanFileSet.

private static File[] scanFileSet(FileSet fs) {
    Project prj = fs.getProject();
    DirectoryScanner scanner = fs.getDirectoryScanner(prj);
    scanner.scan();
    File basedir = scanner.getBasedir();
    String[] fileNames = scanner.getIncludedFiles();
    File[] ret = new File[fileNames.length];
    for (int i = 0; i < fileNames.length; i++) {
        String fileName = fileNames[i];
        ret[i] = new File(basedir, fileName);
    }
    return ret;
}
Also used : Project(org.apache.tools.ant.Project) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) File(java.io.File)

Example 83 with Project

use of org.apache.tools.ant.Project in project build-info by JFrogDev.

the class ArtifactoryBuildListener method doDeploy.

private void doDeploy(BuildEvent event) {
    IvyBuildInfoLog log = getBuildInfoLog(event);
    log.info("[buildinfo:ant] Starting deployment");
    Project project = event.getProject();
    Set<DeployDetails> deployDetails = ctx.getDeployDetails();
    BuildInfoBuilder builder = new BuildInfoBuilder(project.getName()).modules(ctx.getModules()).number("0").durationMillis(System.currentTimeMillis() - ctx.getBuildStartTime()).startedDate(new Date(ctx.getBuildStartTime())).buildAgent(new BuildAgent("Ivy", Ivy.getIvyVersion())).agent(new Agent("Ivy", Ivy.getIvyVersion()));
    ArtifactoryClientConfiguration clientConf = ctx.getClientConf();
    String agentName = clientConf.info.getAgentName();
    String agentVersion = clientConf.info.getAgentVersion();
    if (StringUtils.isNotBlank(agentName) && StringUtils.isNotBlank(agentVersion)) {
        builder.agent(new Agent(agentName, agentVersion));
    }
    String buildAgentName = clientConf.info.getBuildAgentName();
    String buildAgentVersion = clientConf.info.getBuildAgentVersion();
    if (StringUtils.isNotBlank(buildAgentName) && StringUtils.isNotBlank(buildAgentVersion)) {
        builder.buildAgent(new BuildAgent(buildAgentName, buildAgentVersion));
    }
    String buildName = clientConf.info.getBuildName();
    if (StringUtils.isNotBlank(buildName)) {
        builder.name(buildName);
    }
    String buildNumber = clientConf.info.getBuildNumber();
    if (StringUtils.isNotBlank(buildNumber)) {
        builder.number(buildNumber);
    }
    String buildUrl = clientConf.info.getBuildUrl();
    if (StringUtils.isNotBlank(buildUrl)) {
        builder.url(buildUrl);
    }
    String vcsRevision = clientConf.info.getVcsRevision();
    if (StringUtils.isNotBlank(vcsRevision)) {
        builder.vcsRevision(vcsRevision);
    }
    String vcsUrl = clientConf.info.getVcsUrl();
    if (StringUtils.isNotBlank(vcsUrl)) {
        builder.vcsUrl(vcsUrl);
    }
    Vcs vcs = new Vcs(vcsUrl, vcsRevision, clientConf.info.getVcsBranch(), clientConf.info.getVcsMessage());
    if (!vcs.isEmpty()) {
        builder.vcs(Arrays.asList(vcs));
    }
    String artifactoryPluginVersion = clientConf.info.getArtifactoryPluginVersion();
    if (StringUtils.isNotBlank(artifactoryPluginVersion)) {
        builder.artifactoryPluginVersion(artifactoryPluginVersion);
    } else {
        builder.artifactoryPluginVersion("Unknown");
    }
    String principal = clientConf.info.getPrincipal();
    if (StringUtils.isNotBlank(principal)) {
        builder.principal(principal);
    }
    String parentBuildName = clientConf.info.getParentBuildName();
    if (StringUtils.isNotBlank(parentBuildName)) {
        builder.parentName(parentBuildName);
    }
    String parentBuildNumber = clientConf.info.getParentBuildNumber();
    if (StringUtils.isNotBlank(parentBuildNumber)) {
        builder.parentNumber(parentBuildNumber);
    }
    String issueTrackerName = clientConf.info.issues.getIssueTrackerName();
    if (StringUtils.isNotBlank(issueTrackerName)) {
        Issues issues = new Issues();
        issues.setAggregateBuildIssues(clientConf.info.issues.getAggregateBuildIssues());
        issues.setAggregationBuildStatus(clientConf.info.issues.getAggregationBuildStatus());
        issues.setTracker(new IssueTracker(issueTrackerName, clientConf.info.issues.getIssueTrackerVersion()));
        Set<Issue> affectedIssuesSet = clientConf.info.issues.getAffectedIssuesSet();
        if (!affectedIssuesSet.isEmpty()) {
            issues.setAffectedIssues(affectedIssuesSet);
        }
        builder.issues(issues);
    }
    for (Map.Entry<String, String> runParam : clientConf.info.getRunParameters().entrySet()) {
        MatrixParameter matrixParameter = new MatrixParameter(runParam.getKey(), runParam.getValue());
        builder.addRunParameters(matrixParameter);
    }
    BuildInfo buildInfo = builder.build();
    PackageManagerUtils.collectEnvIfNeeded(clientConf, buildInfo);
    String contextUrl = clientConf.publisher.getContextUrl();
    String username = clientConf.publisher.getUsername();
    String password = clientConf.publisher.getPassword();
    try (ArtifactoryManager artifactoryManager = new ArtifactoryManager(contextUrl, username, password, log)) {
        configureProxy(clientConf, artifactoryManager);
        configConnectionTimeout(clientConf, artifactoryManager);
        configRetriesParams(clientConf, artifactoryManager);
        if (clientConf.publisher.isPublishArtifacts()) {
            IncludeExcludePatterns patterns = new IncludeExcludePatterns(clientConf.publisher.getIncludePatterns(), clientConf.publisher.getExcludePatterns());
            deployArtifacts(project, artifactoryManager, deployDetails, patterns);
        }
        if (clientConf.publisher.isPublishBuildInfo()) {
            Utils.sendBuildAndBuildRetention(artifactoryManager, buildInfo, clientConf);
        }
        isDidDeploy = true;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : ArtifactoryClientConfiguration(org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration) Agent(org.jfrog.build.extractor.ci.Agent) BuildAgent(org.jfrog.build.extractor.ci.BuildAgent) DeployDetails(org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails) Issue(org.jfrog.build.extractor.ci.Issue) Issues(org.jfrog.build.extractor.ci.Issues) IssueTracker(org.jfrog.build.extractor.ci.IssueTracker) MatrixParameter(org.jfrog.build.extractor.ci.MatrixParameter) Vcs(org.jfrog.build.extractor.ci.Vcs) IncludeExcludePatterns(org.jfrog.build.extractor.clientConfiguration.IncludeExcludePatterns) IOException(java.io.IOException) BuildAgent(org.jfrog.build.extractor.ci.BuildAgent) Date(java.util.Date) Project(org.apache.tools.ant.Project) BuildInfoBuilder(org.jfrog.build.extractor.builder.BuildInfoBuilder) ArtifactoryManager(org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager) BuildInfo(org.jfrog.build.extractor.ci.BuildInfo) IvyBuildInfoLog(org.jfrog.build.util.IvyBuildInfoLog) Map(java.util.Map)

Example 84 with Project

use of org.apache.tools.ant.Project in project build-info by JFrogDev.

the class ArtifactoryBuildInfoTrigger method collectDependencyInformation.

/**
 * Collect dependency information during the build.
 *
 * @param event The end of resolution Ivy event
 */
private void collectDependencyInformation(IvyEvent event) {
    Project project = (Project) IvyContext.peekInContextStack(IvyTask.ANT_PROJECT_CONTEXT_KEY);
    ResolveReport report = ((EndResolveEvent) event).getReport();
    @SuppressWarnings("unchecked") Map<String, String> attributes = event.getAttributes();
    Module module = getOrCreateModule(attributes);
    project.log("[buildinfo:collect] Collecting dependencies for " + module.getId(), Project.MSG_INFO);
    if (module.getDependencies() == null || module.getDependencies().isEmpty()) {
        String[] configurations = report.getConfigurations();
        List<Dependency> moduleDependencies = new ArrayList<>();
        for (String configuration : configurations) {
            project.log("[buildinfo:collect] Configuration: " + configuration + " Dependencies", Project.MSG_DEBUG);
            ConfigurationResolveReport configurationReport = report.getConfigurationReport(configuration);
            ArtifactDownloadReport[] allArtifactsReports = configurationReport.getAllArtifactsReports();
            for (final ArtifactDownloadReport artifactsReport : allArtifactsReports) {
                project.log("[buildinfo:collect] Artifact Download Report for configuration: " + configuration + " : " + artifactsReport, Project.MSG_DEBUG);
                ModuleRevisionId id = artifactsReport.getArtifact().getModuleRevisionId();
                String type = getType(artifactsReport.getArtifact());
                Dependency dependency = findDependencyInList(id, type, moduleDependencies);
                if (dependency == null) {
                    DependencyBuilder dependencyBuilder = new DependencyBuilder();
                    dependencyBuilder.type(type).scopes(CommonUtils.newHashSet(configuration));
                    String idString = getModuleIdString(id.getOrganisation(), id.getName(), id.getRevision());
                    dependencyBuilder.id(idString);
                    File file = artifactsReport.getLocalFile();
                    Map<String, String> checksums;
                    try {
                        checksums = FileChecksumCalculator.calculateChecksums(file, MD5_ALGORITHM, SHA1_ALGORITHM, SHA256_ALGORITHM);
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                    String md5 = checksums.get(MD5_ALGORITHM);
                    String sha1 = checksums.get(SHA1_ALGORITHM);
                    String sha256 = checksums.get(SHA256_ALGORITHM);
                    dependencyBuilder.md5(md5).sha1(sha1).sha256(sha256);
                    dependency = dependencyBuilder.build();
                    moduleDependencies.add(dependency);
                    project.log("[buildinfo:collect] Added dependency '" + dependency.getId() + "'", Project.MSG_DEBUG);
                } else {
                    if (!dependency.getScopes().contains(configuration)) {
                        dependency.getScopes().add(configuration);
                        project.log("[buildinfo:collect] Added scope " + configuration + " to dependency '" + dependency.getId() + "'", Project.MSG_DEBUG);
                    } else {
                        project.log("[buildinfo:collect] Find same dependency twice in configuration '" + configuration + "' for dependency '" + artifactsReport + "'", Project.MSG_WARN);
                    }
                }
            }
        }
        module.setDependencies(moduleDependencies);
    }
}
Also used : ArrayList(java.util.ArrayList) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) BuildInfoExtractorUtils.getModuleIdString(org.jfrog.build.extractor.BuildInfoExtractorUtils.getModuleIdString) BuildInfoExtractorUtils.getTypeString(org.jfrog.build.extractor.BuildInfoExtractorUtils.getTypeString) Dependency(org.jfrog.build.extractor.ci.Dependency) EndResolveEvent(org.apache.ivy.core.event.resolve.EndResolveEvent) Project(org.apache.tools.ant.Project) ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) ResolveReport(org.apache.ivy.core.report.ResolveReport) DependencyBuilder(org.jfrog.build.extractor.builder.DependencyBuilder) ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) Module(org.jfrog.build.extractor.ci.Module) File(java.io.File)

Example 85 with Project

use of org.apache.tools.ant.Project in project build-info by JFrogDev.

the class ArtifactoryBuildListener method getEventManager.

/**
 * Retrieves all the event managers of all the ivy settings of the project.
 *
 * @param task the task we need to attach listeners to
 * @return the list of event manager for this task
 */
private List<EventManager> getEventManager(Task task) {
    List<EventManager> results = new ArrayList<EventManager>();
    Project project = task.getProject();
    Enumeration<Object> elements = project.getReferences().elements();
    // Iterate the project elements, search for ivy:settings and return them:
    while (elements.hasMoreElements()) {
        Object element = elements.nextElement();
        if (element instanceof UnknownElement) {
            UnknownElement unknown = (UnknownElement) element;
            element = unknown.getRealThing();
            if (element == null) {
                unknown.maybeConfigure();
                element = unknown.getRealThing();
            }
        }
        if (element instanceof IvyAntSettings) {
            results.add(((IvyAntSettings) element).getConfiguredIvyInstance(task).getResolveEngine().getEventManager());
        }
    }
    // If no ivy:settings were found (the ivy script might not include them), return the resolve engine:
    if (results.isEmpty()) {
        ResolveEngine engine = IvyAntSettings.getDefaultInstance(task).getConfiguredIvyInstance(task).getResolveEngine();
        results.add(engine.getEventManager());
    }
    return results;
}
Also used : ResolveEngine(org.apache.ivy.core.resolve.ResolveEngine) Project(org.apache.tools.ant.Project) EventManager(org.apache.ivy.core.event.EventManager) IvyAntSettings(org.apache.ivy.ant.IvyAntSettings) ArrayList(java.util.ArrayList) UnknownElement(org.apache.tools.ant.UnknownElement)

Aggregations

Project (org.apache.tools.ant.Project)331 File (java.io.File)125 Test (org.junit.Test)107 BuildException (org.apache.tools.ant.BuildException)66 Path (org.apache.tools.ant.types.Path)44 IOException (java.io.IOException)38 Before (org.junit.Before)36 FileSet (org.apache.tools.ant.types.FileSet)24 Commandline (org.apache.tools.ant.types.Commandline)22 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)16 Path (java.nio.file.Path)14 DefaultLogger (org.apache.tools.ant.DefaultLogger)14 Test (org.junit.jupiter.api.Test)14 Matchers.containsString (org.hamcrest.Matchers.containsString)13 ZipFile (java.util.zip.ZipFile)12 DirectoryScanner (org.apache.tools.ant.DirectoryScanner)12 Delete (org.apache.tools.ant.taskdefs.Delete)12 Properties (java.util.Properties)9 ProjectHelper (org.apache.tools.ant.ProjectHelper)9 ArrayList (java.util.ArrayList)8