Skip to content

Commit

Permalink
Initial import of http://easyant.org/svn/easyant@650 with trunks and …
Browse files Browse the repository at this point in the history
…not the branches

git-svn-id: https://svn.apache.org/repos/asf/incubator/easyant/tasks/trunk@1071697 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Nicolas Lalevee committed Feb 17, 2011
0 parents commit 556a969
Show file tree
Hide file tree
Showing 27 changed files with 2,261 additions and 0 deletions.
26 changes: 26 additions & 0 deletions mavenivy-adapters/module.ivy
@@ -0,0 +1,26 @@
<ivy-module version="2.0" xmlns:ea="http://www.easyant.org">
<info organisation="org.apache.easyant.tasks" module="mavenivy-adapters"
status="integration" revision="0.1">
<ea:build module="build-std-java" revision="0.2">
<ea:property name="project.ivy.instance" value="easyant.ivy.instance"/>
<ea:property name="release.resolver" value="easyant-shared-modules"/>
<ea:property name="shared.resolver" value="easyant-shared-modules"/>
<ea:property name="local.resolver" value="easyant-shared-modules"/>
</ea:build>
</info>
<configurations>
<conf name="default" visibility="public" description="runtime dependencies artifact can be used with this conf"/>
<conf name="test" visibility="private" description="this scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases."/>
<conf name="provided" visibility="public" description="this is much like compile, but indicates you expect the JDK or a container to provide it. It is only available on the compilation classpath, and is not transitive."/>

</configurations>
<dependencies>
<dependency org="org.apache.maven" name="maven-ant-tasks" rev="2.1.0" conf="default->default">
<exclude org="ant" module="ant"/>
</dependency>
<dependency org="org.apache.ivy" name="ivy" rev="2.1.0" conf="provided->default"/>
<dependency org="junit" name="junit" rev="4.4" conf="test->default"/>
<dependency org="org.apache.ant" name="ant" rev="1.8.1" conf="provided->default"/>
<dependency org="org.apache.ant" name="ant-testutil" rev="1.8.1" conf="test->default" transitive="false" />
</dependencies>
</ivy-module>
@@ -0,0 +1,117 @@
/*
* Copyright 2008-2010 the EasyAnt project
*
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.easyant.ivy;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.ivy.ant.IvyTask;
import org.apache.ivy.core.IvyContext;
import org.apache.ivy.core.IvyPatternHelper;
import org.apache.ivy.core.event.IvyEvent;
import org.apache.ivy.plugins.resolver.DependencyResolver;
import org.apache.ivy.plugins.resolver.IBiblioResolver;
import org.apache.ivy.plugins.resolver.URLResolver;
import org.apache.ivy.plugins.trigger.AbstractTrigger;
import org.apache.ivy.plugins.trigger.Trigger;
import org.apache.tools.ant.Project;

public class MavenPublishTrigger extends AbstractTrigger implements Trigger {

public static final String MAVEN_PUBLISH_TRIGGER_REFERENCE ="maven.publish.trigger.ref";
private List<PublishedArtifact> publishedArtifacts = new ArrayList<PublishedArtifact>();
private String publishUrl = null;

public MavenPublishTrigger() {
super();
}

@Override
public void progress(IvyEvent event) {

Project project = (Project) IvyContext
.peekInContextStack(IvyTask.ANT_PROJECT_CONTEXT_KEY);
if (project == null) {
return;
}
if (project.getReference(MAVEN_PUBLISH_TRIGGER_REFERENCE) == null) {
project.addReference(MAVEN_PUBLISH_TRIGGER_REFERENCE, this);
}

Map attributes = event.getAttributes();
String artifact = (String) attributes.get("artifact");
String artifactFile = (String) attributes.get("file");
String type = (String) attributes.get("type");
String ext = (String) attributes.get("ext");
String resolver = (String) attributes.get("resolver");

PublishedArtifact publishedArtifact = new PublishedArtifact();
publishedArtifact.setArtifact(artifact);
publishedArtifact.setExt(ext);
publishedArtifact.setFile(artifactFile);
publishedArtifact.setType(type);

publishedArtifacts.add(publishedArtifact);

extractDeployUrl(resolver);

}

/**
* @param resolver
*/
protected void extractDeployUrl(String resolver) {
//try to get publish url if the Resolver used to publish was a IBiblioResolver
if (publishUrl == null) {
DependencyResolver dependencyResolver = IvyContext.getContext()
.getSettings().getResolver(resolver);
if (dependencyResolver instanceof IBiblioResolver) {
IBiblioResolver ibiblioResolver = (IBiblioResolver) dependencyResolver;
publishUrl = ibiblioResolver.getRoot();
} else if (dependencyResolver instanceof URLResolver) {
URLResolver urlResolver = (URLResolver) dependencyResolver;
//get the whole pattern
publishUrl = (String) urlResolver.getArtifactPatterns().get(0);
//only keep the token root
publishUrl = IvyPatternHelper.getTokenRoot(publishUrl);

}
}
}

public List<PublishedArtifact> getPublishedArtifacts() {
return publishedArtifacts;
}

public void setPublishedArtifacts(List<PublishedArtifact> publishedArtifacts) {
this.publishedArtifacts = publishedArtifacts;
}

public String getPublishUrl() {
return publishUrl;
}

public void setPublishUrl(String publishUrl) {
this.publishUrl = publishUrl;
}



}
@@ -0,0 +1,62 @@
/*
* Copyright 2008-2010 the EasyAnt project
*
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.easyant.ivy;

public class PublishedArtifact {

private String artifact;
private String type;
private String ext;
private String resolver;
private String file;

public String getArtifact() {
return artifact;
}
public void setArtifact(String artifact) {
this.artifact = artifact;
}
public String getExt() {
return ext;
}
public void setExt(String ext) {
this.ext = ext;
}
public String getResolver() {
return resolver;
}
public void setResolver(String resolver) {
this.resolver = resolver;
}
public String getFile() {
return file;
}
public void setFile(String file) {
this.file = file;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}



}
@@ -0,0 +1,141 @@
/*
* Copyright 2008-2010 the EasyAnt project
*
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.easyant.tasks;

import org.apache.ivy.ant.IvyTask;
import org.apache.ivy.plugins.trigger.AbstractTrigger;
import org.apache.ivy.plugins.trigger.Trigger;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Reference;
import org.apache.tools.ant.util.ClasspathUtils;

public class RegisterTrigger extends IvyTask {
private String event;
private String eventFilter;
private String className;
private Path classpath;

@Override
public void doExecute() throws BuildException {

Trigger trigger = (Trigger) ClasspathUtils.newInstance(getClassName(),
getClassLoader(), Trigger.class);
if (trigger instanceof AbstractTrigger) {
AbstractTrigger abstractTrigger = (AbstractTrigger) trigger;
abstractTrigger.setEvent(getEvent());
getSettings().addTrigger(abstractTrigger);
getIvyInstance().getEventManager().addIvyListener(trigger, trigger.getEventFilter());
}

}

public String getEvent() {
return event;
}

public void setEvent(String event) {
this.event = event;
}



public String getEventFilter() {
return eventFilter;
}

public void setEventFilter(String eventFilter) {
this.eventFilter = eventFilter;
}

/**
* Get the classname to register
*
* @return a classname
*/
public String getClassName() {
return className;
}

/**
* Set the classname to register
*
* @param className
* a classname
*/
public void setClassName(String className) {
this.className = className;
}

protected AntClassLoader getClassLoader() {
// defining a new specialized classloader and setting it as the thread
// context classloader
AntClassLoader loader = null;
if (classpath != null) {
loader = new AntClassLoader(this.getClass().getClassLoader(),
getProject(), classpath, true);
} else {
loader = new AntClassLoader(this.getClass().getClassLoader(), true);
}
loader.setThreadContextLoader();
return loader;
}

/**
* Get the classpath used to locate the specified classname
*
* @return a classpath
*/
public Path getClasspath() {
return classpath;
}

/**
* The the classpath used to locate the specified classname
*
* @param classpath
*/
public void setClasspath(Path classpath) {
createClasspath().append(classpath);
}

/**
* Classpath to use, by reference, when compiling the rulebase
*
* @param a
* reference to an existing classpath
*/
public void setClasspathref(Reference r) {
createClasspath().setRefid(r);
}

/**
* Adds a path to the classpath.
*
* @return created classpath
*/
public Path createClasspath() {
if (this.classpath == null) {
this.classpath = new Path(getProject());
}
return this.classpath.createPath();
}

}

0 comments on commit 556a969

Please sign in to comment.