| 1 |
/* |
| 2 |
* Licensed to the Apache Software Foundation (ASF) under one |
| 3 |
* or more contributor license agreements. See the NOTICE file |
| 4 |
* distributed with this work for additional information |
| 5 |
* regarding copyright ownership. The ASF licenses this file |
| 6 |
* to you under the Apache License, Version 2.0 (the |
| 7 |
* "License"); you may not use this file except in compliance |
| 8 |
* with the License. You may obtain a copy of the License at |
| 9 |
* |
| 10 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 11 |
* |
| 12 |
* Unless required by applicable law or agreed to in writing, |
| 13 |
* software distributed under the License is distributed on an |
| 14 |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 |
* KIND, either express or implied. See the License for the |
| 16 |
* specific language governing permissions and limitations |
| 17 |
* under the License. |
| 18 |
*/ |
| 19 |
package org.apache.maven.doxia.tools.stubs; |
| 20 |
|
| 21 |
import java.io.File; |
| 22 |
import java.io.FileInputStream; |
| 23 |
import java.util.ArrayList; |
| 24 |
import java.util.Collections; |
| 25 |
import java.util.List; |
| 26 |
import java.util.Properties; |
| 27 |
|
| 28 |
import org.apache.maven.RepositoryUtils; |
| 29 |
import org.apache.maven.artifact.repository.ArtifactRepository; |
| 30 |
import org.apache.maven.artifact.repository.DefaultArtifactRepository; |
| 31 |
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; |
| 32 |
import org.apache.maven.model.Build; |
| 33 |
import org.apache.maven.model.DistributionManagement; |
| 34 |
import org.apache.maven.model.Model; |
| 35 |
import org.apache.maven.model.Site; |
| 36 |
import org.apache.maven.model.io.xpp3.MavenXpp3Reader; |
| 37 |
import org.eclipse.aether.repository.RemoteRepository; |
| 38 |
|
| 39 |
/** |
| 40 |
* @author <a href="mailto:[email protected]">Vincent Siveton</a> |
| 41 |
*/ |
| 42 |
public class SiteToolMavenProjectStub extends MavenProjectStub { |
| 43 |
private Build build; |
| 44 |
|
| 45 |
private File basedir; |
| 46 |
|
| 47 |
private DistributionManagement distributionManagement; |
| 48 |
|
| 49 |
private Properties properties; |
| 50 |
|
| 51 |
public SiteToolMavenProjectStub(String projectName) { |
| 52 |
basedir = new File(super.getBasedir() + "/src/test/resources/unit/" + projectName); |
| 53 |
|
| 54 |
Model model = null; |
| 55 |
|
| 56 |
try { |
| 57 |
model = new MavenXpp3Reader().read(new FileInputStream(new File(getBasedir(), "pom.xml"))); |
| 58 |
setModel(model); |
| 59 |
} catch (Exception e) { |
| 60 |
throw new RuntimeException(e); |
| 61 |
} |
| 62 |
|
| 63 |
setGroupId(model.getGroupId()); |
| 64 |
setArtifactId(model.getArtifactId()); |
| 65 |
setVersion(model.getVersion()); |
| 66 |
setName(model.getName()); |
| 67 |
setUrl(model.getUrl()); |
| 68 |
setPackaging(model.getPackaging()); |
| 69 |
setProperties(model.getProperties()); |
| 70 |
|
| 71 |
build = new Build(); |
| 72 |
build.setFinalName(model.getArtifactId()); |
| 73 |
build.setDirectory(super.getBasedir() + "/target/test/unit/" + projectName + "/target"); |
| 74 |
build.setSourceDirectory(getBasedir() + "/src/main/java"); |
| 75 |
build.setOutputDirectory(build.getDirectory() + "/classes"); |
| 76 |
build.setTestSourceDirectory(getBasedir() + "/src/test/java"); |
| 77 |
build.setTestOutputDirectory(build.getDirectory() + "/test-classes"); |
| 78 |
|
| 79 |
List<String> compileSourceRoots = new ArrayList<>(); |
| 80 |
compileSourceRoots.add(getBasedir() + "/src/main/java"); |
| 81 |
setCompileSourceRoots(compileSourceRoots); |
| 82 |
|
| 83 |
List<String> testCompileSourceRoots = new ArrayList<>(); |
| 84 |
testCompileSourceRoots.add(getBasedir() + "/src/test/java"); |
| 85 |
setTestCompileSourceRoots(testCompileSourceRoots); |
| 86 |
} |
| 87 |
|
| 88 |
/** {@inheritDoc} */ |
| 89 |
public Build getBuild() { |
| 90 |
return build; |
| 91 |
} |
| 92 |
|
| 93 |
/** {@inheritDoc} */ |
| 94 |
public void setBuild(Build build) { |
| 95 |
this.build = build; |
| 96 |
} |
| 97 |
|
| 98 |
/** {@inheritDoc} */ |
| 99 |
public File getBasedir() { |
| 100 |
return basedir; |
| 101 |
} |
| 102 |
|
| 103 |
/** {@inheritDoc} */ |
| 104 |
public void setBasedir(File basedir) { |
| 105 |
this.basedir = basedir; |
| 106 |
} |
| 107 |
|
| 108 |
/** {@inheritDoc} */ |
| 109 |
public List<ArtifactRepository> getRemoteArtifactRepositories() { |
| 110 |
ArtifactRepository repository = new DefaultArtifactRepository( |
| 111 |
"central", "https://repo1.maven.org/maven2", new DefaultRepositoryLayout()); |
| 112 |
|
| 113 |
return Collections.singletonList(repository); |
| 114 |
} |
| 115 |
|
| 116 |
/** {@inheritDoc} */ |
| 117 |
public List<RemoteRepository> getRemoteProjectRepositories() { |
| 118 |
return RepositoryUtils.toRepos(getRemoteArtifactRepositories()); |
| 119 |
} |
| 120 |
|
| 121 |
/** {@inheritDoc} */ |
| 122 |
public Properties getProperties() { |
| 123 |
return properties; |
| 124 |
} |
| 125 |
|
| 126 |
/** {@inheritDoc} */ |
| 127 |
public void setProperties(Properties properties) { |
| 128 |
this.properties = properties; |
| 129 |
} |
| 130 |
|
| 131 |
public void setDistgributionManagementSiteUrl(String url) { |
| 132 |
Site site = new Site(); |
| 133 |
site.setUrl(url); |
| 134 |
distributionManagement = new DistributionManagement(); |
| 135 |
distributionManagement.setSite(site); |
| 136 |
} |
| 137 |
|
| 138 |
/** {@inheritDoc} */ |
| 139 |
public DistributionManagement getDistributionManagement() { |
| 140 |
return distributionManagement; |
| 141 |
} |
| 142 |
} |