001: package org.apache.maven.project;
002:
003: /*
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: import org.apache.maven.artifact.Artifact;
023: import org.apache.maven.artifact.handler.ArtifactHandler;
024: import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
025: import org.apache.maven.model.Resource;
026: import org.apache.maven.project.artifact.AttachedArtifact;
027:
028: import java.io.File;
029: import java.util.List;
030:
031: public class DefaultMavenProjectHelper implements MavenProjectHelper {
032:
033: private ArtifactHandlerManager artifactHandlerManager;
034:
035: public void attachArtifact(MavenProject project,
036: String artifactType, String artifactClassifier,
037: File artifactFile) {
038: String type = artifactType;
039:
040: ArtifactHandler handler = null;
041:
042: if (type != null) {
043: handler = artifactHandlerManager
044: .getArtifactHandler(artifactType);
045: }
046:
047: if (handler == null) {
048: handler = artifactHandlerManager.getArtifactHandler("jar");
049: }
050:
051: Artifact artifact = new AttachedArtifact(project.getArtifact(),
052: artifactType, artifactClassifier, handler);
053:
054: artifact.setFile(artifactFile);
055: artifact.setResolved(true);
056:
057: project.addAttachedArtifact(artifact);
058: }
059:
060: public void attachArtifact(MavenProject project,
061: String artifactType, File artifactFile) {
062: ArtifactHandler handler = artifactHandlerManager
063: .getArtifactHandler(artifactType);
064:
065: Artifact artifact = new AttachedArtifact(project.getArtifact(),
066: artifactType, handler);
067:
068: artifact.setFile(artifactFile);
069: artifact.setResolved(true);
070:
071: project.addAttachedArtifact(artifact);
072: }
073:
074: public void attachArtifact(MavenProject project, File artifactFile,
075: String artifactClassifier) {
076: Artifact projectArtifact = project.getArtifact();
077:
078: Artifact artifact = new AttachedArtifact(projectArtifact,
079: projectArtifact.getType(), artifactClassifier,
080: projectArtifact.getArtifactHandler());
081:
082: artifact.setFile(artifactFile);
083: artifact.setResolved(true);
084:
085: project.addAttachedArtifact(artifact);
086: }
087:
088: public void addResource(MavenProject project,
089: String resourceDirectory, List includes, List excludes) {
090: Resource resource = new Resource();
091: resource.setDirectory(resourceDirectory);
092: resource.setIncludes(includes);
093: resource.setExcludes(excludes);
094:
095: project.addResource(resource);
096: }
097:
098: public void addTestResource(MavenProject project,
099: String resourceDirectory, List includes, List excludes) {
100: Resource resource = new Resource();
101: resource.setDirectory(resourceDirectory);
102: resource.setIncludes(includes);
103: resource.setExcludes(excludes);
104:
105: project.addTestResource(resource);
106: }
107:
108: }
|