public NotationParser<Object, MavenArtifact> create() { FileNotationConverter fileNotationConverter = new FileNotationConverter(fileResolver); ArchiveTaskNotationConverter archiveTaskNotationConverter = new ArchiveTaskNotationConverter(); PublishArtifactNotationConverter publishArtifactNotationConverter = new PublishArtifactNotationConverter(); NotationParser<Object, MavenArtifact> sourceNotationParser = NotationParserBuilder .toType(MavenArtifact.class) .fromType(AbstractArchiveTask.class, archiveTaskNotationConverter) .fromType(PublishArtifact.class, publishArtifactNotationConverter) .converter(fileNotationConverter) .toComposite(); MavenArtifactMapNotationConverter mavenArtifactMapNotationConverter = new MavenArtifactMapNotationConverter(sourceNotationParser); NotationParserBuilder<MavenArtifact> parserBuilder = NotationParserBuilder .toType(MavenArtifact.class) .fromType(AbstractArchiveTask.class, archiveTaskNotationConverter) .fromType(PublishArtifact.class, publishArtifactNotationConverter) .converter(mavenArtifactMapNotationConverter) .converter(fileNotationConverter); return parserBuilder.toComposite(); }
public NotationParser<Object, MavenArtifact> create() { FileNotationParser fileNotationParser = new FileNotationParser(fileResolver); ArchiveTaskNotationParser archiveTaskNotationParser = new ArchiveTaskNotationParser(); PublishArtifactNotationParser publishArtifactNotationParser = new PublishArtifactNotationParser(); NotationParser<Object, MavenArtifact> sourceNotationParser = NotationParserBuilder .toType(MavenArtifact.class) .fromType(AbstractArchiveTask.class, archiveTaskNotationParser) .fromType(PublishArtifact.class, publishArtifactNotationParser) .converter(fileNotationParser) .toComposite(); MavenArtifactMapNotationParser mavenArtifactMapNotationParser = new MavenArtifactMapNotationParser(sourceNotationParser); NotationParserBuilder<MavenArtifact> parserBuilder = NotationParserBuilder .toType(MavenArtifact.class) .fromType(AbstractArchiveTask.class, archiveTaskNotationParser) .fromType(PublishArtifact.class, publishArtifactNotationParser) .parser(mavenArtifactMapNotationParser) .converter(fileNotationParser); return parserBuilder.toComposite(); }
File getOutputJar() { String realClassifier = (!getClassifier().isEmpty() ? "-" : "") + getClassifier(); AbstractArchiveTask archiveTask; if (inputTask != null) { archiveTask = inputTask; } else { Set<Task> tasks = getProject().getTasksByName("jar", false); archiveTask = tasks.size() > 0 ? (AbstractArchiveTask)tasks.toArray()[0] : null; } return new File(getInputJar().getParent(), outputJarName != null ? outputJarName + (!outputJarName.endsWith(".jar") ? ".jar" : "") : (archiveTask != null ? archiveTask.getArchiveName().replace("-" + archiveTask.getClassifier(), "") + realClassifier : getInputJar().getName().replace(".jar", "" + realClassifier + ".jar")) ); }
public void convert(AbstractArchiveTask archiveTask, NotationConvertResult<? super MavenArtifact> result) throws TypeConversionException { DefaultMavenArtifact artifact = instantiator.newInstance( DefaultMavenArtifact.class, archiveTask.getArchivePath(), archiveTask.getExtension(), archiveTask.getClassifier()); artifact.builtBy(archiveTask); result.converted(artifact); }
private String getTypeIdentifier(PublishArtifact artifact) { if (artifact instanceof ArchivePublishArtifact) { ArchivePublishArtifact publishArtifact = (ArchivePublishArtifact) artifact; AbstractArchiveTask task = publishArtifact.getArchiveTask(); // There is an inheritance hierarchy in play here, so the order // of the clauses is very important. if (task instanceof War) { return WAR_ARTIFACT.getTypeIdentifier(); } else if (task instanceof Ear) { return EAR_ARTIFACT.getTypeIdentifier(); } else if (task instanceof Jar) { return JAR_ARTIFACT.getTypeIdentifier(); } else if (task instanceof Zip) { return ZIP_ARTIFACT.getTypeIdentifier(); } else if (task instanceof Tar) { return TAR_ARTIFACT.getTypeIdentifier(); } else { // we don't know about this kind of archive task return ARCHIVE_ARTIFACT.getTypeIdentifier(); } } else { // This could very well be a zip (or something else we understand), but we can't know for sure. // The client may try to infer from the file extension. return UNKNOWN_ARTIFACT.getTypeIdentifier(); } }
@Override protected IvyArtifact parseType(AbstractArchiveTask archiveTask) { DefaultIvyArtifact ivyArtifact = createDefaultIvyArtifact( archiveTask.getArchivePath(), archiveTask.getExtension(), archiveTask.getExtension(), archiveTask.getClassifier()); ivyArtifact.builtBy(archiveTask); return ivyArtifact; }
/** * Configures the task to sign the archive produced for each of the given tasks (which must be archive tasks). */ public void sign(Task... tasks) { for (Task task : tasks) { if (!(task instanceof AbstractArchiveTask)) { throw new InvalidUserDataException("You cannot sign tasks that are not \'archive\' tasks, such as \'jar\', \'zip\' etc. (you tried to sign " + String.valueOf(task) + ")"); } signTask((AbstractArchiveTask) task); } }
private void signTask(final AbstractArchiveTask archiveTask) { dependsOn(archiveTask); addSignature(new Signature(new Callable<File>() { public File call() { return archiveTask.getArchivePath(); } }, new Callable<String>() { public String call() { return archiveTask.getClassifier(); } }, this, this)); }
private <T extends AbstractArchiveTask> Task configureArchiveTask(Project project, String taskName, final Distribution distribution, Class<T> type) { final T archiveTask = project.getTasks().create(taskName, type); archiveTask.setDescription("Bundles the project as a distribution."); archiveTask.setGroup(DISTRIBUTION_GROUP); archiveTask.getConventionMapping().map("baseName", new Callable<Object>() { @Override public Object call() throws Exception { if (distribution.getBaseName() == null || distribution.getBaseName().equals("")) { throw new GradleException("Distribution baseName must not be null or empty! Check your configuration of the distribution plugin."); } return distribution.getBaseName(); } }); Callable<String> baseDir = new Callable<String>() { @Override public String call() throws Exception { // For backwards compatibility, we need to simulate the exact behaviour of the previously uses Groovy minus operator String toBeRenamedIfExists = "." + archiveTask.getExtension(); return archiveTask.getArchiveName().replaceFirst(toBeRenamedIfExists, ""); } }; CopySpec childSpec = project.copySpec(); childSpec.into(baseDir); childSpec.with(distribution.getContents()); archiveTask.with(childSpec); ArchivePublishArtifact archiveArtifact = new ArchivePublishArtifact(archiveTask); project.getExtensions().getByType(DefaultArtifactPublicationSet.class).addCandidate(archiveArtifact); return archiveTask; }
private void configureArchiveDefaults(final Project project, final BasePluginConvention pluginConvention) { project.getTasks().withType(AbstractArchiveTask.class, new Action<AbstractArchiveTask>() { public void execute(AbstractArchiveTask task) { ConventionMapping taskConventionMapping = task.getConventionMapping(); Callable<File> destinationDir; if (task instanceof Jar) { destinationDir = new Callable<File>() { public File call() throws Exception { return pluginConvention.getLibsDir(); } }; } else { destinationDir = new Callable<File>() { public File call() throws Exception { return pluginConvention.getDistsDir(); } }; } taskConventionMapping.map("destinationDir", destinationDir); taskConventionMapping.map("version", new Callable<String>() { public String call() throws Exception { return project.getVersion() == Project.DEFAULT_VERSION ? null : project.getVersion().toString(); } }); taskConventionMapping.map("baseName", new Callable<String>() { public String call() throws Exception { return pluginConvention.getArchivesBaseName(); } }); } }); }
private void configureOverlay(WarOverlay overlay) { if (overlay.isDeferProvidedConfiguration()) { //Delay this to trick IntelliJ overlay.getWarTask().doFirst(w -> overlay.getWarCopySpec().exclude(element -> overlay.isProvided())); } else { overlay.getWarCopySpec().exclude(element -> overlay.isProvided()); } Object source = overlay.getSource(); if (source instanceof AbstractArchiveTask) { configureOverlay(overlay, (AbstractArchiveTask) source); } else if (source instanceof Project && overlay.getConfigureClosure() == null) { configureOverlay(overlay, (Project) source); } else { Closure configClosure = overlay.getConfigureClosure(); Dependency dependency; if (configClosure == null) { dependency = project.getDependencies().create(source); } else { dependency = project.getDependencies().create(source, configClosure); } if (dependency instanceof ProjectDependency) { configureOverlay(overlay, ((ProjectDependency) dependency).getDependencyProject()); } else if (dependency instanceof ExternalDependency) { configureOverlay(overlay, (ExternalDependency) dependency); } else { throw new GradleException("Unsupported dependency type: " + dependency.getClass().getName()); } } }
@Override public void apply(final Project project) { explodedArchives = project.getExtensions().create("explodedArchives", ExplodedArchivesExtension.class); explodeAll = project.getTasks().create("explode"); explodeAll.setGroup(BasePlugin.BUILD_GROUP); project.getTasks().withType(AbstractArchiveTask.class, archiveTask -> { Sync explodeArchive = project.getTasks().create("explode" + capitalize((CharSequence) archiveTask.getName()), Sync.class); explodeAll.dependsOn(explodeArchive); explodeArchive.dependsOn(archiveTask); explodeArchive.getConventionMapping() .map("group", (Callable<String>) archiveTask::getGroup); explodeArchive.getConventionMapping() .map("destinationDir", (Callable<File>) () -> { File explodedDir = new File(archiveTask.getDestinationDir(), "exploded"); if (explodedArchives.isIncludeExtension()) { return new File(explodedDir, archiveTask.getArchiveName()); } else { return new File(explodedDir, minus((CharSequence) archiveTask.getArchiveName(), "." + archiveTask.getExtension())); } }); explodeArchive.from((Callable<FileTree>) () -> project.zipTree(archiveTask.getArchivePath())); }); }
private void configureArchiveTask(AbstractArchiveTask archiveTask) { if (archiveTask == null) { return; } archiveTask.dependsOn("_createSourceContext"); archiveTask.from( extension.getOutputDirectory(), new Action<CopySpec>() { @Override public void execute(CopySpec copySpec) { copySpec.into("WEB-INF/classes"); } }); }
@Override public void apply(final Project project) { final UploadPluginExtension extension = project.getExtensions().create("artifactory", UploadPluginExtension.class); //define the artifactory closure extension.setFolder(project.getGroup() + "/" + project.getName() + "/" + project.getVersion()); final UploadTask upload = project.getTasks().create("uploadToArtifactory", UploadTask.class); //define the upload task //make sure tasks that generate artifacts happen first for(final Task task : project.getTasks()){ if(task instanceof AbstractArchiveTask){ logger.debug("Adding dependsOn {} for uploadToArtifactory", task.getName()); upload.dependsOn(task); } } }
@Override protected MavenArtifact parseType(AbstractArchiveTask archiveTask) { DefaultMavenArtifact artifact = instantiator.newInstance( DefaultMavenArtifact.class, archiveTask.getArchivePath(), archiveTask.getExtension(), archiveTask.getClassifier()); artifact.builtBy(archiveTask); return artifact; }
private ArchiveTaskNotationConverter() { super(AbstractArchiveTask.class); }
@Override protected ConfigurablePublishArtifact parseType(AbstractArchiveTask notation) { return instantiator.newInstance(ArchivePublishArtifact.class, notation); }
public ArchivePublishArtifact(AbstractArchiveTask archiveTask) { super(archiveTask); this.archiveTask = archiveTask; }
public AbstractArchiveTask getArchiveTask() { return archiveTask; }
@Finalize void fixupDistributionArchiveNames(AbstractArchiveTask archiveTask) { archiveTask.setArchiveName(archiveTask.getBaseName() + "." + archiveTask.getExtension()); }
private void configureOverlay(WarOverlay overlay, AbstractArchiveTask from) { overlay.getWarCopySpec().with(from.getRootSpec()); }
private AbstractArchiveTask getDistZip(Project project) { return (AbstractArchiveTask) project.getTasks().getByName("distZip"); }
private ArchiveTaskNotationParser() { super(AbstractArchiveTask.class); }
@Override protected PublishArtifact parseType(AbstractArchiveTask notation) { return instantiator.newInstance(ArchivePublishArtifact.class, notation); }