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"));
}
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;
}
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);
}
}
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);
}
}
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;
}
Aggregations