com.sap.prd.mobile.ios.mios.XCodePackageXcodeprojMojo Maven / Gradle / Ivy
Go to download
This plugin is used to run iOS Xcode builds with Maven. It also uses the Maven integration with a
central artifact repository and the dependency resolution.
/*
* #%L
* xcode-maven-plugin
* %%
* Copyright (C) 2012 SAP AG
* %%
* 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.
* #L%
*/
package com.sap.prd.mobile.ios.mios;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProjectHelper;
/**
* Packages the Xcode project with all its resolved binary dependencies. I.e. this archive can be
* unzipped and directly opened in Xcode. It uses the zip
command for packaging. The
* zip command is called with the -y
options to preserver symbolic links and the
* -r
option to follow the paths recursively. The following files and folders get
* packaged:
*
* -
*
src/xcode/
(or the directory specified by the Maven parameter xcode.sourceDirectory
* in you changed the default Xcode project location)
* pom.xml
* sync.info
* target/bundles/
* target/headers/
* target/libs/
* target/xcode-deps/
*
*
* You can use the {@link #additionalArchivePaths} and the {@link #excludes}
*
* If called from command line you have to call mvn initialize
before in order to make
* sure that all binary dependencies have been retrieved from the command line.
*
* Please note that this goal is not part of the default lifecycle for xcode-lib and xcode-app
* projects.
*
* @goal package-xcodeproj
*
*/
public class XCodePackageXcodeprojMojo extends AbstractXCodeMojo
{
public static final String XCODEPROJ_WITH_DEPS_CLASSIFIER = "xcodeproj-with-deps";
/**
* You can use this parameter to define additional paths that shall be packaged into the source
* archive. If the path denotes a folder the folder content with all subfolders will be added. If
* the path points to a file only the file will be added.
*
* Plugin configuration example:
*
*
* <build>
* <plugins>
* <plugin>
* <groupId>com.sap.prd.mobile.ios.mios</groupId>
* <artifactId>xcode-maven-plugin</artifactId>
* <extensions>true</extensions>
* <configuration>
* <additionalArchivePaths>
* <param>src/docs</param>
* <param>src/uml</param>
* ...
* </additionalArchivePaths>
* </configuration>
* </plugin>
* ...
* </plugins>
* </build>
* </build>
*
*
* @parameter
* @since 1.3.2
*/
private List additionalArchivePaths;
/**
* Specify files or file patterns to be excluded from the archive.
*
* Configuration example:
*
*
* <build>
* <plugins>
* <plugin>
* <groupId>com.sap.prd.mobile.ios.mios</groupId>
* <artifactId>xcode-maven-plugin</artifactId>
* <extensions>true</extensions>
* <configuration>
* <excludes>
* <param>*.tmp</param>
* <param>*/tmp/*</param>
* ...
* </excludes>
* </configuration>
* </plugin>
* ...
* </plugins>
* </build>
* </build>
*
*
* @parameter
* @since 1.3.3
*/
private List excludes;
/**
* @component
*/
private MavenProjectHelper projectHelper;
@Override
public void execute() throws MojoExecutionException, MojoFailureException
{
String xprojZipFileName = project.getArtifactId() + "-" + XCODEPROJ_WITH_DEPS_CLASSIFIER + ".zip";
final String projectBuildDirectory = project.getBuild().getDirectory();
try {
final File targetFolder = new File(projectBuildDirectory);
FileUtils.mkdirs(targetFolder);
String relativeTargetDirName = FileUtils.getRelativePath(projectBuildDirectory, project.getBasedir()
.getAbsolutePath(), "/");
String relativeSrcDirName = FileUtils.getRelativePath(FolderLayout.getSourceFolder(project).getAbsolutePath(),
project.getBasedir().getAbsolutePath(), "/");
Set includes = new HashSet();
includes.add(relativeSrcDirName); // src/xcode folder
includes.add(relativeTargetDirName + "/xcode-deps/frameworks");
zip(Arrays.asList("zip", "-r", "-y", "-q", relativeTargetDirName + "/" + xprojZipFileName), includes, excludes);
includes.clear();
includes.add("pom.xml");
includes.add("sync.info");
includes.add(relativeTargetDirName + "/bundles");
includes.add(relativeTargetDirName + "/headers");
includes.add(relativeTargetDirName + "/libs");
includes.add(relativeTargetDirName + "/xcode-deps");
Collection myExcludes = excludes == null ? new ArrayList() : new ArrayList(excludes);
myExcludes.add(relativeTargetDirName + "/xcode-deps/frameworks/*");
if (additionalArchivePaths != null) {
includes.addAll(additionalArchivePaths);
}
zip(Arrays.asList("zip", "-r", "-g", "-q", relativeTargetDirName + "/" + xprojZipFileName), includes, myExcludes);
getLog().info("Packaged the Xcode project with all its dependencies into the zip file " + xprojZipFileName);
}
catch (IOException e) {
throw new MojoExecutionException(
"Could not package the Xcode project with all its dependencies into a zip file.", e);
}
projectHelper.attachArtifact(project, "zip", XCODEPROJ_WITH_DEPS_CLASSIFIER, new File(projectBuildDirectory, xprojZipFileName));
}
private void zip(List zipCommandParts, Collection includes, Collection excludes)
throws IOException, MojoExecutionException
{
ArrayList zipCmdCall = new ArrayList();
zipCmdCall.addAll(zipCommandParts);
zipCmdCall.addAll(includes);
if (excludes != null && !excludes.isEmpty()) {
zipCmdCall.add("-x");
zipCmdCall.addAll(excludes);
}
getLog().info("Executing: " + StringUtils.join(zipCmdCall, ' '));
int exitCode = Forker.forkProcess(System.out, project.getBasedir(), zipCmdCall.toArray(new String[] {}));
if (exitCode != 0) {
throw new MojoExecutionException(
"Could not package the Xcode project with all its dependencies into a zip file.");
}
}
}