Java tutorial
package uk.co.trenddevs.plugin.cba.stubs; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.io.File; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; import org.apache.maven.artifact.Artifact; import org.apache.maven.model.Model; import org.apache.maven.model.Organization; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.PlexusTestCase; public class CbaMavenProjectStub extends MavenProject { private List attachedArtifacts; public CbaMavenProjectStub() { this("src/test/resources/unit/basic-cba-test/plugin-config.xml"); } public CbaMavenProjectStub(String file) { super(new Model()); super.setGroupId("org.apache.maven.test"); super.setArtifactId("maven-cba-test"); super.setVersion("1.0-SNAPSHOT"); super.setDescription("Test description"); Organization org = new Organization(); org.setName("organization"); org.setUrl("http://www.trenddevs.co.uk"); super.setOrganization(org); super.setFile(new File(getBasedir(), file)); super.setPluginArtifacts(Collections.EMPTY_SET); super.setReportArtifacts(Collections.EMPTY_SET); super.setExtensionArtifacts(Collections.EMPTY_SET); super.setArtifact(getArtifact()); super.setRemoteArtifactRepositories(Collections.EMPTY_LIST); super.setPluginArtifactRepositories(Collections.EMPTY_LIST); super.setCollectedProjects(Collections.EMPTY_LIST); super.setActiveProfiles(Collections.EMPTY_LIST); super.addCompileSourceRoot(getBasedir() + "/src/test/resources/unit/basic-cba-test/src/main/java"); super.addTestCompileSourceRoot(getBasedir() + "/src/test/resources/unit/basic-cba-test/src/test/java"); super.setExecutionRoot(false); } public File getBasedir() { return new File(PlexusTestCase.getBasedir()); } public Artifact getArtifact() { return new CbaArtifactStub(getGroupId(), getArtifactId(), getVersion()); } public Set getArtifacts() { Set artifacts = new HashSet(); artifacts.add(createArtifact("org.apache.maven.test", "maven-artifact01", "1.0-SNAPSHOT", false)); artifacts.add(createArtifact("org.apache.maven.test", "maven-artifact02", "1.0-SNAPSHOT", false)); return artifacts; } @Override public Set getDependencyArtifacts() { return getArtifacts(); } public List getAttachedArtifacts() { if (attachedArtifacts == null) attachedArtifacts = new ArrayList(); return attachedArtifacts; } protected Artifact createArtifact(String groupId, String artifactId, String version, boolean optional) { Artifact artifact = new CbaArtifactStub(); artifact.setGroupId(groupId); artifact.setArtifactId(artifactId); artifact.setVersion(version); artifact.setOptional(optional); artifact.setFile(new File(getBasedir() + "/src/test/remote-repo/" + artifact.getGroupId().replace('.', '/') + "/" + artifact.getArtifactId() + "/" + artifact.getVersion() + "/" + artifact.getArtifactId() + "-" + artifact.getVersion() + ".jar")); return artifact; } }