You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by mc...@apache.org on 2008/01/25 09:10:28 UTC
svn commit: r615140 [2/4] -
/felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/
Modified: felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrDeployFile.java
URL: http://svn.apache.org/viewvc/felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrDeployFile.java?rev=615140&r1=615139&r2=615140&view=diff
==============================================================================
--- felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrDeployFile.java (original)
+++ felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrDeployFile.java Fri Jan 25 00:10:25 2008
@@ -1,352 +1,352 @@
-/*
- * 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 org.apache.felix.obr.plugin;
-
-
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.Writer;
-
-import org.apache.maven.artifact.manager.WagonManager;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-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 org.apache.maven.settings.Settings;
-import org.apache.maven.wagon.ResourceDoesNotExistException;
-import org.apache.maven.wagon.TransferFailedException;
-import org.apache.maven.wagon.authorization.AuthorizationException;
-
-
-/**
- * deploy the bundle to a ftp site.
- * this goal is used when you upload a jar file (in command line)
- * @goal deploy-file
- * @phase deploy
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-public class ObrDeployFile extends AbstractMojo
-{
-
- /**
- * setting of maven.
- *
- * @parameter expression="${settings}"
- * @require
- */
-
- private Settings m_settings;
-
- /**
- * name of the repository xml descriptor file.
- *
- * @parameter expression="${repository-name}" default-value="repository.xml"
- */
- private String m_repositoryName;
-
- /**
- * The local Maven repository.
- *
- * @parameter expression="${localRepository}"
- * @required
- */
- private ArtifactRepository m_localRepo;
-
- /**
- * Project in use.
- *
- * @parameter expression="${project}"
- * @require
- */
- private MavenProject m_project;
-
- /**
- * Wagon Manager.
- * @component
- */
- private WagonManager m_wagonManager;
-
- /**
- * obr file define by the user.
- *
- * @parameter expression="${obr-file}"
- *
- */
- private String m_obrFile;
-
- /**
- * obr file define by the user.
- *
- * @parameter expression="${ignore-lock}"
- *
- */
- private boolean m_ignoreLock;
-
- /**
- * used to store pathfile in local repo.
- */
- private String m_fileInLocalRepo;
-
-
- /**
- * main method for this goal.
- * @implements org.apache.maven.plugin.Mojo.execute
- * @throws MojoExecutionException if the plugin failed
- * @throws MojoFailureException if the plugin failed
- */
- public void execute() throws MojoExecutionException, MojoFailureException
- {
- getLog().info( "Obr-deploy-file start:" );
-
- ArtifactRepository ar = m_project.getDistributionManagementArtifactRepository();
-
- // locate the obr.xml file
- PathFile fileObrXml = new PathFile( m_obrFile );
- if ( !fileObrXml.isExists() )
- {
- getLog().warn( "obr.xml file not found, use default" );
- }
-
- File repoDescriptorFile = null;
-
- RemoteFileManager remoteFile = new RemoteFileManager( ar, m_wagonManager, m_settings, getLog() );
-
- remoteFile.connect();
-
- // create a non-empty file used to lock the repository descriptor file
- File lockFile = null;
- Writer output = null;
- try
- {
- lockFile = File.createTempFile( String.valueOf( System.currentTimeMillis() ), null );
- output = new BufferedWriter( new FileWriter( lockFile ) );
- output.write( "locked" );
- output.close();
- }
- catch ( IOException e )
- {
- getLog().error( "Unable to create temporary file" );
- throw new MojoFailureException( "IOException" );
- }
-
- if ( m_ignoreLock )
- {
- try
- {
- remoteFile.put( lockFile, m_repositoryName + ".lock" );
- }
- catch ( TransferFailedException e )
- {
- getLog().error( "Transfer failed" );
- e.printStackTrace();
- throw new MojoFailureException( "TransferFailedException" );
-
- }
- catch ( ResourceDoesNotExistException e )
- {
- throw new MojoFailureException( "ResourceDoesNotExistException" );
- }
- catch ( AuthorizationException e )
- {
- getLog().error( "Authorization failed" );
- e.printStackTrace();
- throw new MojoFailureException( "AuthorizationException" );
- }
-
- }
- else
- {
- int countError = 0;
- while ( remoteFile.isLockedFile( remoteFile, m_repositoryName ) && countError < 2 )
- {
- countError++;
- getLog().warn( "File is locked, retry in 10s" );
- try
- {
- Thread.sleep( 10000 );
- }
- catch ( InterruptedException e )
- {
- getLog().warn( "Sleep Interupted" );
- }
- }
-
- if ( countError == 2 )
- {
- getLog().error(
- "File: " + m_repositoryName + " is locked. Try -Dignore-lock=true if you want to force uploading" );
- throw new MojoFailureException( "fileLocked" );
- }
- }
-
- // file is not locked, so we lock it now
- try
- {
- remoteFile.put( lockFile, m_repositoryName + ".lock" );
- }
- catch ( TransferFailedException e )
- {
- getLog().error( "Transfer failed" );
- e.printStackTrace();
- throw new MojoFailureException( "TransferFailedException" );
-
- }
- catch ( ResourceDoesNotExistException e )
- {
- throw new MojoFailureException( "ResourceDoesNotExistException" );
- }
- catch ( AuthorizationException e )
- {
- getLog().error( "Authorization failed" );
- e.printStackTrace();
- throw new MojoFailureException( "AuthorizationException" );
- }
-
- try
- {
- repoDescriptorFile = remoteFile.get( m_repositoryName );
- }
- catch ( TransferFailedException e )
- {
- getLog().error( "Transfer failed" );
- e.printStackTrace();
- throw new MojoFailureException( "TransferFailedException" );
-
- }
- catch ( ResourceDoesNotExistException e )
- {
- // file doesn't exist! create a new one
- getLog().warn( "file specified does not exist: " + m_repositoryName );
- getLog().warn( "Create a new repository descriptor file " + m_repositoryName );
- try
- {
- File f = File.createTempFile( String.valueOf( System.currentTimeMillis() ), null );
- repoDescriptorFile = new File( f.getParent() + File.separator
- + String.valueOf( System.currentTimeMillis() ) + ".xml" );
- }
- catch ( IOException e1 )
- {
- getLog().error( "canno't create temporary file" );
- e1.printStackTrace();
- return;
- }
- }
- catch ( AuthorizationException e )
- {
- getLog().error( "Authorization failed" );
- e.printStackTrace();
- throw new MojoFailureException( "AuthorizationException" );
- }
- catch ( IOException e )
- {
- e.printStackTrace();
- throw new MojoFailureException( "IOException" );
- }
-
- Config userConfig = new Config();
- userConfig.setPathRelative( true );
- userConfig.setRemotely( true );
-
- PathFile file = null;
-
- // get the path to local maven repository
- file = new PathFile( PathFile.uniformSeparator( m_settings.getLocalRepository() ) + File.separator
- + PathFile.uniformSeparator( m_localRepo.pathOf( m_project.getArtifact() ) ) );
- if ( file.isExists() )
- {
- m_fileInLocalRepo = file.getOnlyAbsoluteFilename();
- }
- else
- {
- getLog().error(
- "file not found in local repository: " + m_settings.getLocalRepository() + File.separator
- + m_localRepo.pathOf( m_project.getArtifact() ) );
- return;
- }
-
- file = new PathFile( "file:/" + repoDescriptorFile.getAbsolutePath() );
-
- ObrUpdate obrUpdate = new ObrUpdate( file, fileObrXml.getOnlyAbsoluteFilename(), m_project, m_fileInLocalRepo,
- PathFile.uniformSeparator( m_settings.getLocalRepository() ), userConfig, getLog() );
-
- obrUpdate.updateRepository();
-
- // the reposiroty descriptor file is modified, we upload it on the remote repository
- try
- {
- remoteFile.put( repoDescriptorFile, m_repositoryName );
- }
- catch ( TransferFailedException e )
- {
- getLog().error( "Transfer failed" );
- e.printStackTrace();
- throw new MojoFailureException( "TransferFailedException" );
- }
- catch ( ResourceDoesNotExistException e )
- {
- getLog().error( "Resource does not exist:" + repoDescriptorFile.getName() );
- e.printStackTrace();
- throw new MojoFailureException( "ResourceDoesNotExistException" );
- }
- catch ( AuthorizationException e )
- {
- getLog().error( "Authorization failed" );
- e.printStackTrace();
- throw new MojoFailureException( "AuthorizationException" );
- }
- repoDescriptorFile.delete();
-
- // we remove lockFile activation
- lockFile = null;
- try
- {
- lockFile = File.createTempFile( String.valueOf( System.currentTimeMillis() ), null );
- }
- catch ( IOException e )
- {
- e.printStackTrace();
- throw new MojoFailureException( "IOException" );
- }
- try
- {
- remoteFile.put( lockFile, m_repositoryName + ".lock" );
- }
- catch ( TransferFailedException e )
- {
- getLog().error( "Transfer failed" );
- e.printStackTrace();
- throw new MojoFailureException( "TransferFailedException" );
- }
- catch ( ResourceDoesNotExistException e )
- {
- e.printStackTrace();
- throw new MojoFailureException( "ResourceDoesNotExistException" );
- }
- catch ( AuthorizationException e )
- {
- getLog().error( "Authorization failed" );
- e.printStackTrace();
- throw new MojoFailureException( "AuthorizationException" );
- }
- remoteFile.disconnect();
- }
-}
+/*
+ * 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 org.apache.felix.obr.plugin;
+
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+
+import org.apache.maven.artifact.manager.WagonManager;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+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 org.apache.maven.settings.Settings;
+import org.apache.maven.wagon.ResourceDoesNotExistException;
+import org.apache.maven.wagon.TransferFailedException;
+import org.apache.maven.wagon.authorization.AuthorizationException;
+
+
+/**
+ * deploy the bundle to a ftp site.
+ * this goal is used when you upload a jar file (in command line)
+ * @goal deploy-file
+ * @phase deploy
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class ObrDeployFile extends AbstractMojo
+{
+
+ /**
+ * setting of maven.
+ *
+ * @parameter expression="${settings}"
+ * @require
+ */
+
+ private Settings m_settings;
+
+ /**
+ * name of the repository xml descriptor file.
+ *
+ * @parameter expression="${repository-name}" default-value="repository.xml"
+ */
+ private String m_repositoryName;
+
+ /**
+ * The local Maven repository.
+ *
+ * @parameter expression="${localRepository}"
+ * @required
+ */
+ private ArtifactRepository m_localRepo;
+
+ /**
+ * Project in use.
+ *
+ * @parameter expression="${project}"
+ * @require
+ */
+ private MavenProject m_project;
+
+ /**
+ * Wagon Manager.
+ * @component
+ */
+ private WagonManager m_wagonManager;
+
+ /**
+ * obr file define by the user.
+ *
+ * @parameter expression="${obr-file}"
+ *
+ */
+ private String m_obrFile;
+
+ /**
+ * obr file define by the user.
+ *
+ * @parameter expression="${ignore-lock}"
+ *
+ */
+ private boolean m_ignoreLock;
+
+ /**
+ * used to store pathfile in local repo.
+ */
+ private String m_fileInLocalRepo;
+
+
+ /**
+ * main method for this goal.
+ * @implements org.apache.maven.plugin.Mojo.execute
+ * @throws MojoExecutionException if the plugin failed
+ * @throws MojoFailureException if the plugin failed
+ */
+ public void execute() throws MojoExecutionException, MojoFailureException
+ {
+ getLog().info( "Obr-deploy-file start:" );
+
+ ArtifactRepository ar = m_project.getDistributionManagementArtifactRepository();
+
+ // locate the obr.xml file
+ PathFile fileObrXml = new PathFile( m_obrFile );
+ if ( !fileObrXml.isExists() )
+ {
+ getLog().warn( "obr.xml file not found, use default" );
+ }
+
+ File repoDescriptorFile = null;
+
+ RemoteFileManager remoteFile = new RemoteFileManager( ar, m_wagonManager, m_settings, getLog() );
+
+ remoteFile.connect();
+
+ // create a non-empty file used to lock the repository descriptor file
+ File lockFile = null;
+ Writer output = null;
+ try
+ {
+ lockFile = File.createTempFile( String.valueOf( System.currentTimeMillis() ), null );
+ output = new BufferedWriter( new FileWriter( lockFile ) );
+ output.write( "locked" );
+ output.close();
+ }
+ catch ( IOException e )
+ {
+ getLog().error( "Unable to create temporary file" );
+ throw new MojoFailureException( "IOException" );
+ }
+
+ if ( m_ignoreLock )
+ {
+ try
+ {
+ remoteFile.put( lockFile, m_repositoryName + ".lock" );
+ }
+ catch ( TransferFailedException e )
+ {
+ getLog().error( "Transfer failed" );
+ e.printStackTrace();
+ throw new MojoFailureException( "TransferFailedException" );
+
+ }
+ catch ( ResourceDoesNotExistException e )
+ {
+ throw new MojoFailureException( "ResourceDoesNotExistException" );
+ }
+ catch ( AuthorizationException e )
+ {
+ getLog().error( "Authorization failed" );
+ e.printStackTrace();
+ throw new MojoFailureException( "AuthorizationException" );
+ }
+
+ }
+ else
+ {
+ int countError = 0;
+ while ( remoteFile.isLockedFile( remoteFile, m_repositoryName ) && countError < 2 )
+ {
+ countError++;
+ getLog().warn( "File is locked, retry in 10s" );
+ try
+ {
+ Thread.sleep( 10000 );
+ }
+ catch ( InterruptedException e )
+ {
+ getLog().warn( "Sleep Interupted" );
+ }
+ }
+
+ if ( countError == 2 )
+ {
+ getLog().error(
+ "File: " + m_repositoryName + " is locked. Try -Dignore-lock=true if you want to force uploading" );
+ throw new MojoFailureException( "fileLocked" );
+ }
+ }
+
+ // file is not locked, so we lock it now
+ try
+ {
+ remoteFile.put( lockFile, m_repositoryName + ".lock" );
+ }
+ catch ( TransferFailedException e )
+ {
+ getLog().error( "Transfer failed" );
+ e.printStackTrace();
+ throw new MojoFailureException( "TransferFailedException" );
+
+ }
+ catch ( ResourceDoesNotExistException e )
+ {
+ throw new MojoFailureException( "ResourceDoesNotExistException" );
+ }
+ catch ( AuthorizationException e )
+ {
+ getLog().error( "Authorization failed" );
+ e.printStackTrace();
+ throw new MojoFailureException( "AuthorizationException" );
+ }
+
+ try
+ {
+ repoDescriptorFile = remoteFile.get( m_repositoryName );
+ }
+ catch ( TransferFailedException e )
+ {
+ getLog().error( "Transfer failed" );
+ e.printStackTrace();
+ throw new MojoFailureException( "TransferFailedException" );
+
+ }
+ catch ( ResourceDoesNotExistException e )
+ {
+ // file doesn't exist! create a new one
+ getLog().warn( "file specified does not exist: " + m_repositoryName );
+ getLog().warn( "Create a new repository descriptor file " + m_repositoryName );
+ try
+ {
+ File f = File.createTempFile( String.valueOf( System.currentTimeMillis() ), null );
+ repoDescriptorFile = new File( f.getParent() + File.separator
+ + String.valueOf( System.currentTimeMillis() ) + ".xml" );
+ }
+ catch ( IOException e1 )
+ {
+ getLog().error( "canno't create temporary file" );
+ e1.printStackTrace();
+ return;
+ }
+ }
+ catch ( AuthorizationException e )
+ {
+ getLog().error( "Authorization failed" );
+ e.printStackTrace();
+ throw new MojoFailureException( "AuthorizationException" );
+ }
+ catch ( IOException e )
+ {
+ e.printStackTrace();
+ throw new MojoFailureException( "IOException" );
+ }
+
+ Config userConfig = new Config();
+ userConfig.setPathRelative( true );
+ userConfig.setRemotely( true );
+
+ PathFile file = null;
+
+ // get the path to local maven repository
+ file = new PathFile( PathFile.uniformSeparator( m_settings.getLocalRepository() ) + File.separator
+ + PathFile.uniformSeparator( m_localRepo.pathOf( m_project.getArtifact() ) ) );
+ if ( file.isExists() )
+ {
+ m_fileInLocalRepo = file.getOnlyAbsoluteFilename();
+ }
+ else
+ {
+ getLog().error(
+ "file not found in local repository: " + m_settings.getLocalRepository() + File.separator
+ + m_localRepo.pathOf( m_project.getArtifact() ) );
+ return;
+ }
+
+ file = new PathFile( "file:/" + repoDescriptorFile.getAbsolutePath() );
+
+ ObrUpdate obrUpdate = new ObrUpdate( file, fileObrXml.getOnlyAbsoluteFilename(), m_project, m_fileInLocalRepo,
+ PathFile.uniformSeparator( m_settings.getLocalRepository() ), userConfig, getLog() );
+
+ obrUpdate.updateRepository();
+
+ // the reposiroty descriptor file is modified, we upload it on the remote repository
+ try
+ {
+ remoteFile.put( repoDescriptorFile, m_repositoryName );
+ }
+ catch ( TransferFailedException e )
+ {
+ getLog().error( "Transfer failed" );
+ e.printStackTrace();
+ throw new MojoFailureException( "TransferFailedException" );
+ }
+ catch ( ResourceDoesNotExistException e )
+ {
+ getLog().error( "Resource does not exist:" + repoDescriptorFile.getName() );
+ e.printStackTrace();
+ throw new MojoFailureException( "ResourceDoesNotExistException" );
+ }
+ catch ( AuthorizationException e )
+ {
+ getLog().error( "Authorization failed" );
+ e.printStackTrace();
+ throw new MojoFailureException( "AuthorizationException" );
+ }
+ repoDescriptorFile.delete();
+
+ // we remove lockFile activation
+ lockFile = null;
+ try
+ {
+ lockFile = File.createTempFile( String.valueOf( System.currentTimeMillis() ), null );
+ }
+ catch ( IOException e )
+ {
+ e.printStackTrace();
+ throw new MojoFailureException( "IOException" );
+ }
+ try
+ {
+ remoteFile.put( lockFile, m_repositoryName + ".lock" );
+ }
+ catch ( TransferFailedException e )
+ {
+ getLog().error( "Transfer failed" );
+ e.printStackTrace();
+ throw new MojoFailureException( "TransferFailedException" );
+ }
+ catch ( ResourceDoesNotExistException e )
+ {
+ e.printStackTrace();
+ throw new MojoFailureException( "ResourceDoesNotExistException" );
+ }
+ catch ( AuthorizationException e )
+ {
+ getLog().error( "Authorization failed" );
+ e.printStackTrace();
+ throw new MojoFailureException( "AuthorizationException" );
+ }
+ remoteFile.disconnect();
+ }
+}
Modified: felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrInstallFile.java
URL: http://svn.apache.org/viewvc/felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrInstallFile.java?rev=615140&r1=615139&r2=615140&view=diff
==============================================================================
--- felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrInstallFile.java (original)
+++ felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrInstallFile.java Fri Jan 25 00:10:25 2008
@@ -1,198 +1,198 @@
-/*
- * 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 org.apache.felix.obr.plugin;
-
-
-import java.io.File;
-
-import org.apache.maven.artifact.repository.ArtifactRepository;
-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 org.apache.maven.settings.Settings;
-
-
-/**
- * construct the repository.xml from a compiled bundle.
- * @description construct the repository.xml from a compiled bundle.
- * @goal install-file
- * @requiresProject false
- * @phase install
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-public class ObrInstallFile extends AbstractMojo
-{
- /**
- * The local Maven repository.
- *
- * @parameter expression="${localRepository}"
- * @required
- */
- private ArtifactRepository m_localRepo;
-
- /**
- * path to the repository.xml.
- *
- * @parameter expression="${repository-path}"
- * @require
- */
- private String m_repositoryPath;
-
- /**
- * setting of maven.
- *
- * @parameter expression="${settings}"
- * @require
- */
- private Settings m_settings;
-
- /**
- * Artifact Id.
- * @description symbolic name define by the user
- * @parameter expression="${artifactId}"
- */
- private String m_artifactId;
-
- /**
- * Group Id.
- * @description groupId define by the user
- * @parameter expression="${groupId}"
- */
- private String m_groupId;
-
- /**
- * Version.
- * @description version define by the user
- * @parameter expression="${version}"
- */
- private String m_version;
-
- /**
- * Packaging.
- * @description packaging define by the user
- * @parameter expression="${packaging}"
- */
- private String m_packaging;
-
- /**
- * OBR File.
- * @description obr file define by the user
- * @parameter expression="${obr-file}"
- */
- private String m_obrFile;
-
- /**
- * store user information in a project.
- */
- private MavenProject m_project;
-
-
- /**
- * main method for this goal.
- * @implements org.apache.maven.plugin.Mojo.execute
- * @throws MojoExecutionException if the plugin failed
- * @throws MojoFailureException if the plugin failed
- */
- public void execute() throws MojoExecutionException, MojoFailureException
- {
- getLog().info( "Install-File Obr starts:" );
-
- m_project = new MavenProject();
- m_project.setArtifactId( m_artifactId );
- m_project.setGroupId( m_groupId );
- m_project.setVersion( m_version );
- m_project.setPackaging( m_packaging );
-
- PathFile fileOut;
-
- if ( m_groupId == null )
- {
- getLog().error( "-DgroupId=VALUE is required" );
- return;
- }
- if ( m_artifactId == null )
- {
- getLog().error( "-Dartifactid=VALUE is required" );
- return;
- }
- if ( m_version == null )
- {
- getLog().error( "-Dversion=VALUE is required" );
- return;
- }
- if ( m_packaging == null )
- {
- getLog().error( "-Dpackaging=VALUE is required" );
- return;
- }
-
- // copy the file to the local repository
- PathFile repoLocal = new PathFile( m_localRepo.getBasedir() );
-
- // get the target file in mvn repo
- fileOut = new PathFile( PathFile.uniformSeparator( m_settings.getLocalRepository() ) + File.separator
- + m_groupId.replace( '.', File.separatorChar ) + File.separator + m_artifactId + File.separator + m_version
- + File.separator + m_artifactId + "-" + m_version + "." + m_packaging );
-
- if ( !fileOut.isExists() )
- {
- getLog().error( "file doesn't exist: " + fileOut.getAbsoluteFilename() );
- return;
- }
- else
- {
- getLog().info( "Target file: " + fileOut.getAbsoluteFilename() );
- }
-
- if ( m_repositoryPath == null )
- {
- m_repositoryPath = "file:" + repoLocal.getOnlyAbsoluteFilename() + "repository.xml";
- getLog().warn( "-DpathRepo is not define, use default repository: " + m_repositoryPath );
- }
-
- PathFile fileRepo = new PathFile( m_repositoryPath );
- if ( fileRepo.isRelative() )
- {
- fileRepo.setBaseDir( m_settings.getLocalRepository() );
- }
-
- // create the folder to the repository
- PathFile repoExist = new PathFile( fileRepo.getAbsolutePath() );
- if ( !repoExist.isExists() )
- {
- fileRepo.createPath();
- }
-
- PathFile fileObrXml = new PathFile( m_obrFile );
- if ( !fileObrXml.isExists() )
- {
- getLog().warn( "obr.xml file not found, use default" );
- }
-
- // build the user config
- Config userConfig = new Config();
-
- ObrUpdate obrUpdate = new ObrUpdate( fileRepo, fileObrXml.getOnlyAbsoluteFilename(), m_project, fileOut
- .getOnlyAbsoluteFilename(), m_localRepo.getBasedir(), userConfig, getLog() );
- obrUpdate.updateRepository();
-
- }
-
-}
+/*
+ * 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 org.apache.felix.obr.plugin;
+
+
+import java.io.File;
+
+import org.apache.maven.artifact.repository.ArtifactRepository;
+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 org.apache.maven.settings.Settings;
+
+
+/**
+ * construct the repository.xml from a compiled bundle.
+ * @description construct the repository.xml from a compiled bundle.
+ * @goal install-file
+ * @requiresProject false
+ * @phase install
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class ObrInstallFile extends AbstractMojo
+{
+ /**
+ * The local Maven repository.
+ *
+ * @parameter expression="${localRepository}"
+ * @required
+ */
+ private ArtifactRepository m_localRepo;
+
+ /**
+ * path to the repository.xml.
+ *
+ * @parameter expression="${repository-path}"
+ * @require
+ */
+ private String m_repositoryPath;
+
+ /**
+ * setting of maven.
+ *
+ * @parameter expression="${settings}"
+ * @require
+ */
+ private Settings m_settings;
+
+ /**
+ * Artifact Id.
+ * @description symbolic name define by the user
+ * @parameter expression="${artifactId}"
+ */
+ private String m_artifactId;
+
+ /**
+ * Group Id.
+ * @description groupId define by the user
+ * @parameter expression="${groupId}"
+ */
+ private String m_groupId;
+
+ /**
+ * Version.
+ * @description version define by the user
+ * @parameter expression="${version}"
+ */
+ private String m_version;
+
+ /**
+ * Packaging.
+ * @description packaging define by the user
+ * @parameter expression="${packaging}"
+ */
+ private String m_packaging;
+
+ /**
+ * OBR File.
+ * @description obr file define by the user
+ * @parameter expression="${obr-file}"
+ */
+ private String m_obrFile;
+
+ /**
+ * store user information in a project.
+ */
+ private MavenProject m_project;
+
+
+ /**
+ * main method for this goal.
+ * @implements org.apache.maven.plugin.Mojo.execute
+ * @throws MojoExecutionException if the plugin failed
+ * @throws MojoFailureException if the plugin failed
+ */
+ public void execute() throws MojoExecutionException, MojoFailureException
+ {
+ getLog().info( "Install-File Obr starts:" );
+
+ m_project = new MavenProject();
+ m_project.setArtifactId( m_artifactId );
+ m_project.setGroupId( m_groupId );
+ m_project.setVersion( m_version );
+ m_project.setPackaging( m_packaging );
+
+ PathFile fileOut;
+
+ if ( m_groupId == null )
+ {
+ getLog().error( "-DgroupId=VALUE is required" );
+ return;
+ }
+ if ( m_artifactId == null )
+ {
+ getLog().error( "-Dartifactid=VALUE is required" );
+ return;
+ }
+ if ( m_version == null )
+ {
+ getLog().error( "-Dversion=VALUE is required" );
+ return;
+ }
+ if ( m_packaging == null )
+ {
+ getLog().error( "-Dpackaging=VALUE is required" );
+ return;
+ }
+
+ // copy the file to the local repository
+ PathFile repoLocal = new PathFile( m_localRepo.getBasedir() );
+
+ // get the target file in mvn repo
+ fileOut = new PathFile( PathFile.uniformSeparator( m_settings.getLocalRepository() ) + File.separator
+ + m_groupId.replace( '.', File.separatorChar ) + File.separator + m_artifactId + File.separator + m_version
+ + File.separator + m_artifactId + "-" + m_version + "." + m_packaging );
+
+ if ( !fileOut.isExists() )
+ {
+ getLog().error( "file doesn't exist: " + fileOut.getAbsoluteFilename() );
+ return;
+ }
+ else
+ {
+ getLog().info( "Target file: " + fileOut.getAbsoluteFilename() );
+ }
+
+ if ( m_repositoryPath == null )
+ {
+ m_repositoryPath = "file:" + repoLocal.getOnlyAbsoluteFilename() + "repository.xml";
+ getLog().warn( "-DpathRepo is not define, use default repository: " + m_repositoryPath );
+ }
+
+ PathFile fileRepo = new PathFile( m_repositoryPath );
+ if ( fileRepo.isRelative() )
+ {
+ fileRepo.setBaseDir( m_settings.getLocalRepository() );
+ }
+
+ // create the folder to the repository
+ PathFile repoExist = new PathFile( fileRepo.getAbsolutePath() );
+ if ( !repoExist.isExists() )
+ {
+ fileRepo.createPath();
+ }
+
+ PathFile fileObrXml = new PathFile( m_obrFile );
+ if ( !fileObrXml.isExists() )
+ {
+ getLog().warn( "obr.xml file not found, use default" );
+ }
+
+ // build the user config
+ Config userConfig = new Config();
+
+ ObrUpdate obrUpdate = new ObrUpdate( fileRepo, fileObrXml.getOnlyAbsoluteFilename(), m_project, fileOut
+ .getOnlyAbsoluteFilename(), m_localRepo.getBasedir(), userConfig, getLog() );
+ obrUpdate.updateRepository();
+
+ }
+
+}
Modified: felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrUpdate.java
URL: http://svn.apache.org/viewvc/felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrUpdate.java?rev=615140&r1=615139&r2=615140&view=diff
==============================================================================
--- felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrUpdate.java (original)
+++ felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/ObrUpdate.java Fri Jan 25 00:10:25 2008
@@ -1,602 +1,602 @@
-/*
- * 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 org.apache.felix.obr.plugin;
-
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.net.URI;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Properties;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.Result;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.logging.Log;
-import org.apache.maven.project.MavenProject;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.SAXException;
-
-
-/**
- * this class parse the old repository.xml file build the bundle resource description and update the repository.
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-
-public class ObrUpdate
-{
- /**
- * generate the date format to insert it in repository descriptor file.
- */
- static SimpleDateFormat m_format = new SimpleDateFormat( "yyyyMMddHHmmss.SSS" );
-
- /**
- * logger for this plugin.
- */
- private Log m_logger;
-
- /**
- * name and path to the repository descriptor file.
- */
- private URI m_repoFilename;
-
- /**
- * name and path to the obr.xml file.
- */
- private String m_obrXml;
-
- /**
- * name and path to the bundle jar file.
- */
- private String m_outputFile;
-
- /**
- * maven project description.
- */
- private MavenProject m_project;
-
- /**
- * user configuration information.
- */
- private Config m_userConfig;
-
- /**
- * used to build another xml document.
- */
- private DocumentBuilder m_constructor;
-
- /**
- * root on parent document.
- */
- private Document m_repoDoc;
-
- /**
- * first Node on repository descriptor tree.
- */
- private Node m_root;
-
- /**
- * used to extract bindex bundle information.
- */
- private ExtractBindexInfo m_ebi;
-
- /**
- * used to store bundle information.
- */
- private ResourcesBundle m_resourceBundle;
-
- /**
- * pathfile to the repository descriptor file.
- */
- private PathFile m_repo;
-
-
- /**
- * initialize information.
- * @param repoFilename path to the repository descriptor file
- * @param obrXml path and filename to the obr.xml file
- * @param project maven project description
- * @param outputFile path to the bundle jar file
- * @param localRepo only path to the local repository
- * @param userConfig user information
- * @param log plugin logger
- */
- public ObrUpdate( PathFile repoFilename, String obrXml, MavenProject project, String outputFile, String localRepo,
- Config userConfig, Log log )
- {
- // this.m_localRepo = localRepo;
- this.m_outputFile = outputFile;
- this.m_repoFilename = repoFilename.getUri();
- this.m_obrXml = obrXml;
- this.m_project = project;
- this.m_logger = log;
-
- this.m_userConfig = userConfig;
-
- m_resourceBundle = new ResourcesBundle( log );
-
- if ( userConfig.isRemotely() )
- {
- this.m_repo = new PathFile( localRepo );
- }
- else
- {
- this.m_repo = repoFilename;
- }
- }
-
-
- /**
- * update the repository descriptor file. parse the old repository descriptor file, get the old reference of the bundle or determine the id for a new bundle, extract information from bindex set the new information in descriptor file and save it.
- * @throws MojoExecutionException if the plugin failed
- */
- public void updateRepository() throws MojoExecutionException
- {
-
- m_logger.debug( " (f) m_obrXml = " + m_obrXml );
- m_logger.debug( " (f) m_outputFile = " + m_outputFile );
- m_logger.debug( " (f) m_repoFilename = " + m_repoFilename );
-
- m_constructor = initConstructor();
-
- if ( m_constructor == null )
- {
- return;
- }
-
- // get the file size
- PathFile pf = new PathFile( m_outputFile );
- File fout = pf.getFile();
- pf.setBaseDir( m_repo.getOnlyAbsolutePath() );
- if ( fout.exists() )
- {
- m_resourceBundle.setSize( String.valueOf( fout.length() ) );
- if ( m_userConfig.isPathRelative() )
- {
- m_resourceBundle.setUri( pf.getOnlyRelativeFilename().replace( '\\', '/' ) );
- }
- else
- {
- m_resourceBundle.setUri( "file:" + m_outputFile );
- }
- }
- else
- {
- m_logger.error( "file doesn't exist: " + m_outputFile );
- return;
- }
-
- // parse repository
- if ( parseRepositoryXml() == -1 )
- {
- return;
- }
-
- // parse the obr.xml file
- if ( m_obrXml != null )
- {
- // URL url = getClass().getResource("/SchemaObr.xsd");
- // TODO validate obr.xml file
-
- Document obrXmlDoc = parseFile( m_obrXml, m_constructor );
- if ( obrXmlDoc == null )
- {
- return;
- }
- Node obrXmlRoot = ( Element ) obrXmlDoc.getDocumentElement();
- // sort the obr file
- sortObrXml( obrXmlRoot );
- }
-
- // use bindex to extract bundle information
- try
- {
- m_ebi = new ExtractBindexInfo( m_repoFilename, m_outputFile );
- }
- catch ( MojoExecutionException e )
- {
- m_logger.error( "unable to build Bindex informations" );
- e.printStackTrace();
- throw new MojoExecutionException( "MojoFailureException" );
- }
-
- m_resourceBundle.construct( m_project, m_ebi );
-
- if ( !walkOnTree( m_root ) )
- {
- // the correct resource node was not found, we must create it
- // we compute the new id
- String id = m_resourceBundle.getId();
- searchRepository( m_root, id );
- }
-
- // the repository.xml file have been modified, so we save it
- m_logger.info( "Writing OBR metadata" );
- writeToFile( m_repoFilename, m_root );
- }
-
-
- /**
- * init the document builder from xerces.
- * @return DocumentBuilder ready to create new document
- */
- private DocumentBuilder initConstructor()
- {
- DocumentBuilder constructor = null;
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- try
- {
- constructor = factory.newDocumentBuilder();
- }
- catch ( ParserConfigurationException e )
- {
- m_logger.error( "unable to create a new xml document" );
- e.printStackTrace();
- }
- return constructor;
-
- }
-
-
- /**
- * Parse the repository descriptor file.
- *
- * @return 0 if the bundle is already in the descriptor, else -1
- * @throws MojoExecutionException if the plugin failed
- */
- private int parseRepositoryXml() throws MojoExecutionException
- {
-
- File fout = new File( m_repoFilename );
- if ( !fout.exists() )
- {
- // create the repository.xml
- try
- {
- fout.createNewFile();
- m_logger.info( "Created " + fout.getAbsolutePath() );
- }
- catch ( IOException e )
- {
- m_logger.error( "Cannot create file " + fout.getAbsolutePath() );
- e.printStackTrace();
- return -1;
- }
-
- Document doc = m_constructor.newDocument();
- // create xml tree
- Date d = new Date();
- d.setTime( System.currentTimeMillis() );
- Element root = doc.createElement( "repository" );
- root.setAttribute( "lastmodified", m_format.format( d ) );
- root.setAttribute( "name", "MyRepository" );
- try
- {
- writeToFile( m_repoFilename, root );
- }
- catch ( MojoExecutionException e )
- {
- e.printStackTrace();
- throw new MojoExecutionException( "MojoExecutionException" );
- }
- }
-
- // now we parse the repository.xml file
- m_repoDoc = parseFile( fout.getAbsolutePath(), m_constructor );
- if ( m_repoDoc == null )
- {
- return -1;
- }
-
- m_root = ( Element ) m_repoDoc.getDocumentElement();
- return 0;
- }
-
-
- /**
- * transform a xml file to a xerces Document.
- * @param filename path to the xml file
- * @param constructor DocumentBuilder get from xerces
- * @return Document which describe this file
- */
- private Document parseFile( String filename, DocumentBuilder constructor )
- {
- if ( constructor == null )
- {
- return null;
- }
- // The document is the root of the DOM tree.
- m_logger.info( "Parsing " + filename );
- Document doc = null;
- try
- {
- doc = constructor.parse( new File( filename ) );
- }
- catch ( SAXException e )
- {
- e.printStackTrace();
- return null;
- }
- catch ( IOException e )
- {
- m_logger.error( "cannot open file: " + filename );
- e.printStackTrace();
- return null;
- }
- return doc;
- }
-
-
- /**
- * put the information from obr.xml into ressourceBundle object.
- * @param node Node to the OBR.xml file
- */
- private void sortObrXml( Node node )
- {
- if ( node.getNodeName().compareTo( "require" ) == 0 )
- {
- Require newRequireNode = new Require();
- NamedNodeMap list = node.getAttributes();
- try
- {
- newRequireNode.setExtend( list.getNamedItem( "extend" ).getNodeValue() );
- newRequireNode.setMultiple( list.getNamedItem( "multiple" ).getNodeValue() );
- newRequireNode.setOptional( list.getNamedItem( "optional" ).getNodeValue() );
- newRequireNode.setFilter( list.getNamedItem( "filter" ).getNodeValue() );
- newRequireNode.setName( list.getNamedItem( "name" ).getNodeValue() );
- }
- catch ( NullPointerException e )
- {
- m_logger
- .error( "the obr.xml file seems to be invalid in a \"require\" tag (one or more attributes are missing)" );
- // e.printStackTrace();
- }
- newRequireNode.setValue( XmlHelper.getTextContent( node ) );
- m_resourceBundle.addRequire( newRequireNode );
- }
- else if ( node.getNodeName().compareTo( "capability" ) == 0 )
- {
- Capability newCapability = new Capability();
- try
- {
- newCapability.setName( node.getAttributes().getNamedItem( "name" ).getNodeValue() );
- }
- catch ( NullPointerException e )
- {
- m_logger.error( "attribute \"name\" is missing in obr.xml in a \"capability\" tag" );
- e.printStackTrace();
- }
- NodeList list = node.getChildNodes();
- for ( int i = 0; i < list.getLength(); i++ )
- {
- PElement p = new PElement();
- Node n = list.item( i );
- Node item = null;
- // System.err.println(n.getNodeName());
- if ( n.getNodeName().compareTo( "p" ) == 0 )
- {
-
- p.setN( n.getAttributes().getNamedItem( "n" ).getNodeValue() );
- item = n.getAttributes().getNamedItem( "t" );
- if ( item != null )
- {
- p.setT( item.getNodeValue() );
- }
- item = n.getAttributes().getNamedItem( "v" );
- if ( item != null )
- {
- p.setV( item.getNodeValue() );
- }
-
- newCapability.addP( p );
- }
- }
- m_resourceBundle.addCapability( newCapability );
- }
- else if ( node.getNodeName().compareTo( "category" ) == 0 )
- {
- Category newCategory = new Category();
- newCategory.setId( node.getAttributes().getNamedItem( "id" ).getNodeValue() );
- m_resourceBundle.addCategory( newCategory );
- }
- else
- {
- NodeList list = node.getChildNodes();
- for ( int i = 0; i < list.getLength(); i++ )
- {
- sortObrXml( list.item( i ) );
- }
- }
- }
-
-
- /**
- * write a Node in a xml file.
- * @param outputFilename URI to the output file
- * @param treeToBeWrite Node root of the tree to be write in file
- * @throws MojoExecutionException if the plugin failed
- */
- private void writeToFile( URI outputFilename, Node treeToBeWrite ) throws MojoExecutionException
- {
- // init the transformer
- Transformer transformer = null;
- TransformerFactory tfabrique = TransformerFactory.newInstance();
- try
- {
- transformer = tfabrique.newTransformer();
- }
- catch ( TransformerConfigurationException e )
- {
- m_logger.error( "Unable to write to file: " + outputFilename.toString() );
- e.printStackTrace();
- throw new MojoExecutionException( "TransformerConfigurationException" );
- }
- Properties proprietes = new Properties();
- proprietes.put( "method", "xml" );
- proprietes.put( "version", "1.0" );
- proprietes.put( "encoding", "ISO-8859-1" );
- proprietes.put( "standalone", "yes" );
- proprietes.put( "indent", "yes" );
- proprietes.put( "omit-xml-declaration", "no" );
- transformer.setOutputProperties( proprietes );
-
- DOMSource input = new DOMSource( treeToBeWrite );
-
- File fichier = new File( outputFilename );
- FileOutputStream flux = null;
- try
- {
- flux = new FileOutputStream( fichier );
- }
- catch ( FileNotFoundException e )
- {
- m_logger.error( "Unable to write to file: " + fichier.getName() );
- e.printStackTrace();
- throw new MojoExecutionException( "FileNotFoundException" );
- }
- Result output = new StreamResult( flux );
- try
- {
- transformer.transform( input, output );
- }
- catch ( TransformerException e )
- {
- e.printStackTrace();
- throw new MojoExecutionException( "TransformerException" );
- }
-
- try
- {
- flux.flush();
- flux.close();
- }
- catch ( IOException e )
- {
- e.printStackTrace();
- throw new MojoExecutionException( "IOException" );
- }
-
- }
-
-
- /**
- * walk on the tree until the targeted node was found.
- * @param node targeted node
- * @return true if the requiered node was found else false.
- */
- private boolean walkOnTree( Node node )
- {
-
- if ( node.getNodeName().compareTo( "resource" ) == 0 )
- {
- return resource( node );
- }
- else
- { // look at the repository node (first in the file)
- if ( node.getNodeName().compareTo( "repository" ) == 0 )
- {
- Date d = new Date();
- d.setTime( System.currentTimeMillis() );
- NamedNodeMap nList = node.getAttributes();
- Node n = nList.getNamedItem( "lastmodified" );
- n.setNodeValue( m_format.format( d ) );
- }
- NodeList list = node.getChildNodes();
- if ( list.getLength() > 0 )
- {
- for ( int i = 0; i < list.getLength(); i++ )
- {
- if ( walkOnTree( list.item( i ) ) )
- {
- return true;
- }
- }
- }
- return false;
- }
-
- }
-
-
- /**
- * put the resource bundle in the tree.
- * @param node Node on the xml file
- * @param id id of the bundle ressource
- */
- private void searchRepository( Node node, String id )
- {
- if ( node.getNodeName().compareTo( "repository" ) == 0 )
- {
- node.appendChild( m_resourceBundle.getNode( m_repoDoc ) );
- return;
- }
- else
- {
- System.out.println( "Second branch..." );
- NodeList list = node.getChildNodes();
- if ( list.getLength() > 0 )
- {
- for ( int i = 0; i < list.getLength(); i++ )
- {
- searchRepository( list.item( i ), id );
- }
- }
- }
-
- }
-
-
- /**
- * compare two node and update the array which compute the smallest free id.
- * @param node : node
- * @return true if the node is the same bundle than the ressourceBundle, else false.
- */
- private boolean resource( Node node )
- {
-
- // this part save all the id free if we need to add resource
- String id = node.getAttributes().getNamedItem( "id" ).getNodeValue();
- NamedNodeMap map = node.getAttributes();
-
- if ( m_resourceBundle.isSameBundleResource( map.getNamedItem( "symbolicname" ).getNodeValue(), map
- .getNamedItem( "version" ).getNodeValue() ) )
- {
- m_resourceBundle.setId( String.valueOf( id ) );
- node.getParentNode().replaceChild( m_resourceBundle.getNode( m_repoDoc ), node );
- return true;
- }
- return false;
- }
-}
+/*
+ * 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 org.apache.felix.obr.plugin;
+
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.URI;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Properties;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.Result;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+
+/**
+ * this class parse the old repository.xml file build the bundle resource description and update the repository.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+
+public class ObrUpdate
+{
+ /**
+ * generate the date format to insert it in repository descriptor file.
+ */
+ static SimpleDateFormat m_format = new SimpleDateFormat( "yyyyMMddHHmmss.SSS" );
+
+ /**
+ * logger for this plugin.
+ */
+ private Log m_logger;
+
+ /**
+ * name and path to the repository descriptor file.
+ */
+ private URI m_repoFilename;
+
+ /**
+ * name and path to the obr.xml file.
+ */
+ private String m_obrXml;
+
+ /**
+ * name and path to the bundle jar file.
+ */
+ private String m_outputFile;
+
+ /**
+ * maven project description.
+ */
+ private MavenProject m_project;
+
+ /**
+ * user configuration information.
+ */
+ private Config m_userConfig;
+
+ /**
+ * used to build another xml document.
+ */
+ private DocumentBuilder m_constructor;
+
+ /**
+ * root on parent document.
+ */
+ private Document m_repoDoc;
+
+ /**
+ * first Node on repository descriptor tree.
+ */
+ private Node m_root;
+
+ /**
+ * used to extract bindex bundle information.
+ */
+ private ExtractBindexInfo m_ebi;
+
+ /**
+ * used to store bundle information.
+ */
+ private ResourcesBundle m_resourceBundle;
+
+ /**
+ * pathfile to the repository descriptor file.
+ */
+ private PathFile m_repo;
+
+
+ /**
+ * initialize information.
+ * @param repoFilename path to the repository descriptor file
+ * @param obrXml path and filename to the obr.xml file
+ * @param project maven project description
+ * @param outputFile path to the bundle jar file
+ * @param localRepo only path to the local repository
+ * @param userConfig user information
+ * @param log plugin logger
+ */
+ public ObrUpdate( PathFile repoFilename, String obrXml, MavenProject project, String outputFile, String localRepo,
+ Config userConfig, Log log )
+ {
+ // this.m_localRepo = localRepo;
+ this.m_outputFile = outputFile;
+ this.m_repoFilename = repoFilename.getUri();
+ this.m_obrXml = obrXml;
+ this.m_project = project;
+ this.m_logger = log;
+
+ this.m_userConfig = userConfig;
+
+ m_resourceBundle = new ResourcesBundle( log );
+
+ if ( userConfig.isRemotely() )
+ {
+ this.m_repo = new PathFile( localRepo );
+ }
+ else
+ {
+ this.m_repo = repoFilename;
+ }
+ }
+
+
+ /**
+ * update the repository descriptor file. parse the old repository descriptor file, get the old reference of the bundle or determine the id for a new bundle, extract information from bindex set the new information in descriptor file and save it.
+ * @throws MojoExecutionException if the plugin failed
+ */
+ public void updateRepository() throws MojoExecutionException
+ {
+
+ m_logger.debug( " (f) m_obrXml = " + m_obrXml );
+ m_logger.debug( " (f) m_outputFile = " + m_outputFile );
+ m_logger.debug( " (f) m_repoFilename = " + m_repoFilename );
+
+ m_constructor = initConstructor();
+
+ if ( m_constructor == null )
+ {
+ return;
+ }
+
+ // get the file size
+ PathFile pf = new PathFile( m_outputFile );
+ File fout = pf.getFile();
+ pf.setBaseDir( m_repo.getOnlyAbsolutePath() );
+ if ( fout.exists() )
+ {
+ m_resourceBundle.setSize( String.valueOf( fout.length() ) );
+ if ( m_userConfig.isPathRelative() )
+ {
+ m_resourceBundle.setUri( pf.getOnlyRelativeFilename().replace( '\\', '/' ) );
+ }
+ else
+ {
+ m_resourceBundle.setUri( "file:" + m_outputFile );
+ }
+ }
+ else
+ {
+ m_logger.error( "file doesn't exist: " + m_outputFile );
+ return;
+ }
+
+ // parse repository
+ if ( parseRepositoryXml() == -1 )
+ {
+ return;
+ }
+
+ // parse the obr.xml file
+ if ( m_obrXml != null )
+ {
+ // URL url = getClass().getResource("/SchemaObr.xsd");
+ // TODO validate obr.xml file
+
+ Document obrXmlDoc = parseFile( m_obrXml, m_constructor );
+ if ( obrXmlDoc == null )
+ {
+ return;
+ }
+ Node obrXmlRoot = ( Element ) obrXmlDoc.getDocumentElement();
+ // sort the obr file
+ sortObrXml( obrXmlRoot );
+ }
+
+ // use bindex to extract bundle information
+ try
+ {
+ m_ebi = new ExtractBindexInfo( m_repoFilename, m_outputFile );
+ }
+ catch ( MojoExecutionException e )
+ {
+ m_logger.error( "unable to build Bindex informations" );
+ e.printStackTrace();
+ throw new MojoExecutionException( "MojoFailureException" );
+ }
+
+ m_resourceBundle.construct( m_project, m_ebi );
+
+ if ( !walkOnTree( m_root ) )
+ {
+ // the correct resource node was not found, we must create it
+ // we compute the new id
+ String id = m_resourceBundle.getId();
+ searchRepository( m_root, id );
+ }
+
+ // the repository.xml file have been modified, so we save it
+ m_logger.info( "Writing OBR metadata" );
+ writeToFile( m_repoFilename, m_root );
+ }
+
+
+ /**
+ * init the document builder from xerces.
+ * @return DocumentBuilder ready to create new document
+ */
+ private DocumentBuilder initConstructor()
+ {
+ DocumentBuilder constructor = null;
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ try
+ {
+ constructor = factory.newDocumentBuilder();
+ }
+ catch ( ParserConfigurationException e )
+ {
+ m_logger.error( "unable to create a new xml document" );
+ e.printStackTrace();
+ }
+ return constructor;
+
+ }
+
+
+ /**
+ * Parse the repository descriptor file.
+ *
+ * @return 0 if the bundle is already in the descriptor, else -1
+ * @throws MojoExecutionException if the plugin failed
+ */
+ private int parseRepositoryXml() throws MojoExecutionException
+ {
+
+ File fout = new File( m_repoFilename );
+ if ( !fout.exists() )
+ {
+ // create the repository.xml
+ try
+ {
+ fout.createNewFile();
+ m_logger.info( "Created " + fout.getAbsolutePath() );
+ }
+ catch ( IOException e )
+ {
+ m_logger.error( "Cannot create file " + fout.getAbsolutePath() );
+ e.printStackTrace();
+ return -1;
+ }
+
+ Document doc = m_constructor.newDocument();
+ // create xml tree
+ Date d = new Date();
+ d.setTime( System.currentTimeMillis() );
+ Element root = doc.createElement( "repository" );
+ root.setAttribute( "lastmodified", m_format.format( d ) );
+ root.setAttribute( "name", "MyRepository" );
+ try
+ {
+ writeToFile( m_repoFilename, root );
+ }
+ catch ( MojoExecutionException e )
+ {
+ e.printStackTrace();
+ throw new MojoExecutionException( "MojoExecutionException" );
+ }
+ }
+
+ // now we parse the repository.xml file
+ m_repoDoc = parseFile( fout.getAbsolutePath(), m_constructor );
+ if ( m_repoDoc == null )
+ {
+ return -1;
+ }
+
+ m_root = ( Element ) m_repoDoc.getDocumentElement();
+ return 0;
+ }
+
+
+ /**
+ * transform a xml file to a xerces Document.
+ * @param filename path to the xml file
+ * @param constructor DocumentBuilder get from xerces
+ * @return Document which describe this file
+ */
+ private Document parseFile( String filename, DocumentBuilder constructor )
+ {
+ if ( constructor == null )
+ {
+ return null;
+ }
+ // The document is the root of the DOM tree.
+ m_logger.info( "Parsing " + filename );
+ Document doc = null;
+ try
+ {
+ doc = constructor.parse( new File( filename ) );
+ }
+ catch ( SAXException e )
+ {
+ e.printStackTrace();
+ return null;
+ }
+ catch ( IOException e )
+ {
+ m_logger.error( "cannot open file: " + filename );
+ e.printStackTrace();
+ return null;
+ }
+ return doc;
+ }
+
+
+ /**
+ * put the information from obr.xml into ressourceBundle object.
+ * @param node Node to the OBR.xml file
+ */
+ private void sortObrXml( Node node )
+ {
+ if ( node.getNodeName().compareTo( "require" ) == 0 )
+ {
+ Require newRequireNode = new Require();
+ NamedNodeMap list = node.getAttributes();
+ try
+ {
+ newRequireNode.setExtend( list.getNamedItem( "extend" ).getNodeValue() );
+ newRequireNode.setMultiple( list.getNamedItem( "multiple" ).getNodeValue() );
+ newRequireNode.setOptional( list.getNamedItem( "optional" ).getNodeValue() );
+ newRequireNode.setFilter( list.getNamedItem( "filter" ).getNodeValue() );
+ newRequireNode.setName( list.getNamedItem( "name" ).getNodeValue() );
+ }
+ catch ( NullPointerException e )
+ {
+ m_logger
+ .error( "the obr.xml file seems to be invalid in a \"require\" tag (one or more attributes are missing)" );
+ // e.printStackTrace();
+ }
+ newRequireNode.setValue( XmlHelper.getTextContent( node ) );
+ m_resourceBundle.addRequire( newRequireNode );
+ }
+ else if ( node.getNodeName().compareTo( "capability" ) == 0 )
+ {
+ Capability newCapability = new Capability();
+ try
+ {
+ newCapability.setName( node.getAttributes().getNamedItem( "name" ).getNodeValue() );
+ }
+ catch ( NullPointerException e )
+ {
+ m_logger.error( "attribute \"name\" is missing in obr.xml in a \"capability\" tag" );
+ e.printStackTrace();
+ }
+ NodeList list = node.getChildNodes();
+ for ( int i = 0; i < list.getLength(); i++ )
+ {
+ PElement p = new PElement();
+ Node n = list.item( i );
+ Node item = null;
+ // System.err.println(n.getNodeName());
+ if ( n.getNodeName().compareTo( "p" ) == 0 )
+ {
+
+ p.setN( n.getAttributes().getNamedItem( "n" ).getNodeValue() );
+ item = n.getAttributes().getNamedItem( "t" );
+ if ( item != null )
+ {
+ p.setT( item.getNodeValue() );
+ }
+ item = n.getAttributes().getNamedItem( "v" );
+ if ( item != null )
+ {
+ p.setV( item.getNodeValue() );
+ }
+
+ newCapability.addP( p );
+ }
+ }
+ m_resourceBundle.addCapability( newCapability );
+ }
+ else if ( node.getNodeName().compareTo( "category" ) == 0 )
+ {
+ Category newCategory = new Category();
+ newCategory.setId( node.getAttributes().getNamedItem( "id" ).getNodeValue() );
+ m_resourceBundle.addCategory( newCategory );
+ }
+ else
+ {
+ NodeList list = node.getChildNodes();
+ for ( int i = 0; i < list.getLength(); i++ )
+ {
+ sortObrXml( list.item( i ) );
+ }
+ }
+ }
+
+
+ /**
+ * write a Node in a xml file.
+ * @param outputFilename URI to the output file
+ * @param treeToBeWrite Node root of the tree to be write in file
+ * @throws MojoExecutionException if the plugin failed
+ */
+ private void writeToFile( URI outputFilename, Node treeToBeWrite ) throws MojoExecutionException
+ {
+ // init the transformer
+ Transformer transformer = null;
+ TransformerFactory tfabrique = TransformerFactory.newInstance();
+ try
+ {
+ transformer = tfabrique.newTransformer();
+ }
+ catch ( TransformerConfigurationException e )
+ {
+ m_logger.error( "Unable to write to file: " + outputFilename.toString() );
+ e.printStackTrace();
+ throw new MojoExecutionException( "TransformerConfigurationException" );
+ }
+ Properties proprietes = new Properties();
+ proprietes.put( "method", "xml" );
+ proprietes.put( "version", "1.0" );
+ proprietes.put( "encoding", "ISO-8859-1" );
+ proprietes.put( "standalone", "yes" );
+ proprietes.put( "indent", "yes" );
+ proprietes.put( "omit-xml-declaration", "no" );
+ transformer.setOutputProperties( proprietes );
+
+ DOMSource input = new DOMSource( treeToBeWrite );
+
+ File fichier = new File( outputFilename );
+ FileOutputStream flux = null;
+ try
+ {
+ flux = new FileOutputStream( fichier );
+ }
+ catch ( FileNotFoundException e )
+ {
+ m_logger.error( "Unable to write to file: " + fichier.getName() );
+ e.printStackTrace();
+ throw new MojoExecutionException( "FileNotFoundException" );
+ }
+ Result output = new StreamResult( flux );
+ try
+ {
+ transformer.transform( input, output );
+ }
+ catch ( TransformerException e )
+ {
+ e.printStackTrace();
+ throw new MojoExecutionException( "TransformerException" );
+ }
+
+ try
+ {
+ flux.flush();
+ flux.close();
+ }
+ catch ( IOException e )
+ {
+ e.printStackTrace();
+ throw new MojoExecutionException( "IOException" );
+ }
+
+ }
+
+
+ /**
+ * walk on the tree until the targeted node was found.
+ * @param node targeted node
+ * @return true if the requiered node was found else false.
+ */
+ private boolean walkOnTree( Node node )
+ {
+
+ if ( node.getNodeName().compareTo( "resource" ) == 0 )
+ {
+ return resource( node );
+ }
+ else
+ { // look at the repository node (first in the file)
+ if ( node.getNodeName().compareTo( "repository" ) == 0 )
+ {
+ Date d = new Date();
+ d.setTime( System.currentTimeMillis() );
+ NamedNodeMap nList = node.getAttributes();
+ Node n = nList.getNamedItem( "lastmodified" );
+ n.setNodeValue( m_format.format( d ) );
+ }
+ NodeList list = node.getChildNodes();
+ if ( list.getLength() > 0 )
+ {
+ for ( int i = 0; i < list.getLength(); i++ )
+ {
+ if ( walkOnTree( list.item( i ) ) )
+ {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ }
+
+
+ /**
+ * put the resource bundle in the tree.
+ * @param node Node on the xml file
+ * @param id id of the bundle ressource
+ */
+ private void searchRepository( Node node, String id )
+ {
+ if ( node.getNodeName().compareTo( "repository" ) == 0 )
+ {
+ node.appendChild( m_resourceBundle.getNode( m_repoDoc ) );
+ return;
+ }
+ else
+ {
+ System.out.println( "Second branch..." );
+ NodeList list = node.getChildNodes();
+ if ( list.getLength() > 0 )
+ {
+ for ( int i = 0; i < list.getLength(); i++ )
+ {
+ searchRepository( list.item( i ), id );
+ }
+ }
+ }
+
+ }
+
+
+ /**
+ * compare two node and update the array which compute the smallest free id.
+ * @param node : node
+ * @return true if the node is the same bundle than the ressourceBundle, else false.
+ */
+ private boolean resource( Node node )
+ {
+
+ // this part save all the id free if we need to add resource
+ String id = node.getAttributes().getNamedItem( "id" ).getNodeValue();
+ NamedNodeMap map = node.getAttributes();
+
+ if ( m_resourceBundle.isSameBundleResource( map.getNamedItem( "symbolicname" ).getNodeValue(), map
+ .getNamedItem( "version" ).getNodeValue() ) )
+ {
+ m_resourceBundle.setId( String.valueOf( id ) );
+ node.getParentNode().replaceChild( m_resourceBundle.getNode( m_repoDoc ), node );
+ return true;
+ }
+ return false;
+ }
+}
Modified: felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/PElement.java
URL: http://svn.apache.org/viewvc/felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/PElement.java?rev=615140&r1=615139&r2=615140&view=diff
==============================================================================
--- felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/PElement.java (original)
+++ felix/trunk/maven-obr-plugin/src/main/java/org/apache/felix/obr/plugin/PElement.java Fri Jan 25 00:10:25 2008
@@ -1,131 +1,131 @@
-/*
- * 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 org.apache.felix.obr.plugin;
-
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
-
-/**
- * this class describe the p element in a capability tag.
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- *
- */
-public class PElement
-{
- /**
- * store the v tag (value).
- */
- private String m_v;
-
- /**
- * store the t tag (type).
- */
- private String m_t;
-
- /**
- * store the n tag (name).
- */
- private String m_n;
-
-
- /**
- * get the n tag.
- * @return attribute n
- */
- public String getN()
- {
- return m_n;
- }
-
-
- /**
- * set the n tage.
- * @param n new value
- */
- public void setN( String n )
- {
- this.m_n = n;
- }
-
-
- /**
- * get the t tag.
- * @return attribute t
- */
- public String getT()
- {
- return m_t;
- }
-
-
- /**
- * set the t tag.
- * @param t new value
- */
- public void setT( String t )
- {
- this.m_t = t;
- }
-
-
- /**
- * get the v tag.
- * @return attribute v
- */
- public String getV()
- {
- return m_v;
- }
-
-
- /**
- * set the v tag.
- * @param v new value
- */
- public void setV( String v )
- {
- this.m_v = v;
- }
-
-
- /**
- * transform this object to node.
- * @param father father document for create Node
- * @return node
- */
- public Node getNode( Document father )
- {
- Element p = father.createElement( "p" );
- p.setAttribute( "n", this.getN() );
- if ( this.getT() != null )
- {
- p.setAttribute( "t", this.getT() );
- }
-
- if ( this.getV() != null )
- {
- p.setAttribute( "v", this.getV() );
- }
-
- return p;
- }
-}
+/*
+ * 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 org.apache.felix.obr.plugin;
+
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+
+/**
+ * this class describe the p element in a capability tag.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ *
+ */
+public class PElement
+{
+ /**
+ * store the v tag (value).
+ */
+ private String m_v;
+
+ /**
+ * store the t tag (type).
+ */
+ private String m_t;
+
+ /**
+ * store the n tag (name).
+ */
+ private String m_n;
+
+
+ /**
+ * get the n tag.
+ * @return attribute n
+ */
+ public String getN()
+ {
+ return m_n;
+ }
+
+
+ /**
+ * set the n tage.
+ * @param n new value
+ */
+ public void setN( String n )
+ {
+ this.m_n = n;
+ }
+
+
+ /**
+ * get the t tag.
+ * @return attribute t
+ */
+ public String getT()
+ {
+ return m_t;
+ }
+
+
+ /**
+ * set the t tag.
+ * @param t new value
+ */
+ public void setT( String t )
+ {
+ this.m_t = t;
+ }
+
+
+ /**
+ * get the v tag.
+ * @return attribute v
+ */
+ public String getV()
+ {
+ return m_v;
+ }
+
+
+ /**
+ * set the v tag.
+ * @param v new value
+ */
+ public void setV( String v )
+ {
+ this.m_v = v;
+ }
+
+
+ /**
+ * transform this object to node.
+ * @param father father document for create Node
+ * @return node
+ */
+ public Node getNode( Document father )
+ {
+ Element p = father.createElement( "p" );
+ p.setAttribute( "n", this.getN() );
+ if ( this.getT() != null )
+ {
+ p.setAttribute( "t", this.getT() );
+ }
+
+ if ( this.getV() != null )
+ {
+ p.setAttribute( "v", this.getV() );
+ }
+
+ return p;
+ }
+}