Author: lcorneliussen Date: Thu Dec 29 15:45:25 2011 New Revision: 1225570 URL: http://svn.apache.org/viewvc?rev=1225570&view=rev Log: [NPANDAY-518, NPANDAY-488] Packaging for .NET Applications
o handling of configuration files Added: incubator/npanday/trunk/components/dotnet-packaging/src/main/java/npanday/packaging/ConfigFileHandler.java incubator/npanday/trunk/plugins/application-maven-plugin/src/main/java/npanday/plugin/application/ProcessAppConfigMojo.java incubator/npanday/trunk/plugins/aspnet-maven-plugin/src/main/java/npanday/plugin/aspnet/ProcessWebConfigMojo.java Added: incubator/npanday/trunk/components/dotnet-packaging/src/main/java/npanday/packaging/ConfigFileHandler.java URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-packaging/src/main/java/npanday/packaging/ConfigFileHandler.java?rev=1225570&view=auto ============================================================================== --- incubator/npanday/trunk/components/dotnet-packaging/src/main/java/npanday/packaging/ConfigFileHandler.java (added) +++ incubator/npanday/trunk/components/dotnet-packaging/src/main/java/npanday/packaging/ConfigFileHandler.java Thu Dec 29 15:45:25 2011 @@ -0,0 +1,61 @@ +/* + * 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. + */ + +package npanday.packaging; + +import org.apache.maven.plugin.MojoFailureException; +import org.codehaus.plexus.logging.AbstractLogEnabled; +import org.codehaus.plexus.util.FileUtils; + +import java.io.File; +import java.io.IOException; + +/** + * @author <a href="mailto:lcornelius...@apache.org">Lars Corneliussen</a> + * + * @plexus.component role="npanday.packaging.ConfigFileHandler" + */ +public class ConfigFileHandler + extends AbstractLogEnabled +{ + public void handleConfigFile( File sourceConfigFile, File targetConfigFile ) throws MojoFailureException + { + if ( !sourceConfigFile.exists() ) + { + getLogger().warn( "NPANDAY-133-001: The configuration file '" + sourceConfigFile + "' couldn't be found" ); + return; + } + + // TODO: add XDT-support here + + getLogger().info( "NPANDAY-133-004: Transforming/copying config file for packaging" ); + + try + { + getLogger().debug( "NPANDAY-133-002: Copying config file '" + sourceConfigFile + "' to '" + targetConfigFile + "'" ); + FileUtils.copyFile( sourceConfigFile, targetConfigFile ); + } + catch ( IOException e ) + { + throw new MojoFailureException( + "NPANDAY-133-003: Unable to copy config file '" + sourceConfigFile + "' to '" + targetConfigFile + "'" + ); + } + } +} Added: incubator/npanday/trunk/plugins/application-maven-plugin/src/main/java/npanday/plugin/application/ProcessAppConfigMojo.java URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/plugins/application-maven-plugin/src/main/java/npanday/plugin/application/ProcessAppConfigMojo.java?rev=1225570&view=auto ============================================================================== --- incubator/npanday/trunk/plugins/application-maven-plugin/src/main/java/npanday/plugin/application/ProcessAppConfigMojo.java (added) +++ incubator/npanday/trunk/plugins/application-maven-plugin/src/main/java/npanday/plugin/application/ProcessAppConfigMojo.java Thu Dec 29 15:45:25 2011 @@ -0,0 +1,87 @@ +/* + * 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. + */ + +package npanday.plugin.application; + +import npanday.ArtifactType; +import npanday.PathUtil; +import npanday.packaging.ConfigFileHandler; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.project.MavenProject; + +import java.io.File; + +/** + * Takes care of moving a configuration while optionally filtering + * and applying XDT transformations. + * + * @author <a href="mailto:lcornelius...@apache.org">Lars Corneliussen</a> + * + * @phase prepare-package + * @goal process-app-config + * @since 1.5.0-incubating + */ +public class ProcessAppConfigMojo + extends AbstractMojo +{ + /** + * @parameter default-value="false" + */ + private boolean skip; + + /** + * @parameter default-value="${basedir}/app.package.config" + */ + private File appConfig; + + /** + * The maven project. + * + * @parameter expression="${project}" + * @required + */ + protected MavenProject project; + + /** + * @component + */ + protected ConfigFileHandler confiFileHandler; + + public void execute() throws MojoExecutionException, MojoFailureException + { + if ( skip ) + { + getLog().info( "NPANDAY-132-000: Automatic handling of app.config was skipped by configuration" ); + return; + } + + final File sourceConfigFile = appConfig; + + String extension = ArtifactType.getArtifactTypeForPackagingName( project.getPackaging() ).getExtension(); + File targetConfigFile = new File( + PathUtil.getPreparedPackageFolder( project ), project.getArtifactId() + "." + extension + ".config" + ); + + confiFileHandler.handleConfigFile( sourceConfigFile, targetConfigFile ); + } + + +} Added: incubator/npanday/trunk/plugins/aspnet-maven-plugin/src/main/java/npanday/plugin/aspnet/ProcessWebConfigMojo.java URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/plugins/aspnet-maven-plugin/src/main/java/npanday/plugin/aspnet/ProcessWebConfigMojo.java?rev=1225570&view=auto ============================================================================== --- incubator/npanday/trunk/plugins/aspnet-maven-plugin/src/main/java/npanday/plugin/aspnet/ProcessWebConfigMojo.java (added) +++ incubator/npanday/trunk/plugins/aspnet-maven-plugin/src/main/java/npanday/plugin/aspnet/ProcessWebConfigMojo.java Thu Dec 29 15:45:25 2011 @@ -0,0 +1,84 @@ +/* + * 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. + */ + +package npanday.plugin.aspnet; + +import npanday.PathUtil; +import npanday.packaging.ConfigFileHandler; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.project.MavenProject; + +import java.io.File; + +/** + * Takes care of moving a configuration while optionally filtering + * and applying XDT transformations. + * + * @author <a href="mailto:lcornelius...@apache.org">Lars Corneliussen</a> + * + * @phase prepare-package + * @goal process-web-config + * @since 1.5.0-incubating + */ +public class ProcessWebConfigMojo + extends AbstractMojo +{ + /** + * @parameter default-value="false" + */ + private boolean skip; + + /** + * @parameter default-value="${basedir}/web.package.config" + */ + private File webConfig; + + /** + * The maven project. + * + * @parameter expression="${project}" + * @required + */ + protected MavenProject project; + + /** + * @component + */ + protected ConfigFileHandler confiFileHandler; + + public void execute() throws MojoExecutionException, MojoFailureException + { + if ( skip ) + { + getLog().info( "NPANDAY-132-000: Automatic handling of web.config was skipped by configuration" ); + return; + } + + final File sourceConfigFile = webConfig; + File targetConfigFile = new File( + PathUtil.getPreparedPackageFolder( project ), "web.config" + ); + + confiFileHandler.handleConfigFile( sourceConfigFile, targetConfigFile ); + } + + +}