1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
/*******************************************************************************
* Copyright (c) 2012 Eclipse Foundation and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Eclipse Foundation - initial API and implementation
*******************************************************************************/
package org.eclipse.cbi.mojo;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.codehaus.plexus.util.IOUtil;
import org.eclipse.tycho.core.osgitools.BundleReader;
import org.eclipse.tycho.core.osgitools.OsgiManifest;
import org.eclipse.tycho.core.osgitools.OsgiManifestParserException;
abstract class AbstractPluginScannerMojo
extends AbstractMojo
{
/**
* igorf: as of 2012-01-05, generated repository location is hardcoded to target/repository in tycho
*
* @parameter default-value="${project.build.directory}/repository"
**/
protected File repository;
/** @component */
protected BundleReader bundleReader;
public void execute()
throws MojoExecutionException, MojoFailureException
{
try
{
Properties properties = new Properties();
File[] plugins = new File( repository, "plugins" ).listFiles();
if ( plugins != null )
{
Map<File, OsgiManifest> manifests = new HashMap<File, OsgiManifest>();
for ( File plugin : plugins )
{
if ( plugin.getName().endsWith( ".pack.gz" ) )
{
continue;
}
try
{
OsgiManifest manifest = bundleReader.loadManifest( plugin );
manifests.put( plugin, manifest );
}
catch ( OsgiManifestParserException e )
{
getLog().error( e );
}
}
processPlugins( properties, manifests );
}
OutputStream os = new BufferedOutputStream( new FileOutputStream( getDestination() ) );
try
{
properties.store( os, null );
}
finally
{
IOUtil.close( os );
}
}
catch ( Exception e )
{
throw new MojoExecutionException( "Could not write plugin versions", e );
}
}
protected abstract void processPlugins( Properties properties, Map<File, OsgiManifest> plugins )
throws Exception;
protected abstract File getDestination();
}
|