1 package org.apache.maven.plugin.coreit;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.plugin.AbstractMojo;
23 import org.apache.maven.plugin.Mojo;
24 import org.apache.maven.plugin.MojoExecutionException;
25
26 import java.io.File;
27 import java.util.Properties;
28
29
30
31
32
33
34
35
36
37
38 public class AssignmentCompatibleMojo
39 extends AbstractMojo
40 {
41
42
43
44
45
46
47 private File assigncompatPropertiesFile;
48
49
50
51
52
53
54 private String[] classNames;
55
56
57
58
59
60
61 public void execute()
62 throws MojoExecutionException
63 {
64 ClassLoader coreRealm = Mojo.class.getClassLoader();
65 ClassLoader pluginRealm = getClass().getClassLoader();
66
67 if ( coreRealm == pluginRealm )
68 {
69 throw new MojoExecutionException( "Unexpected class loader hierarchy, could not detect core realm" );
70 }
71
72 Properties properties = new Properties();
73
74 if ( classNames != null )
75 {
76 for ( int i = 0; i < classNames.length; i++ )
77 {
78 String className = classNames[i];
79 String result;
80
81 getLog().info( "[MAVEN-CORE-IT-LOG] Loading class " + className );
82
83 try
84 {
85 Class type = pluginRealm.loadClass( className );
86 result = getKey( type );
87 }
88 catch ( ClassNotFoundException e )
89 {
90 result = "";
91 }
92 properties.setProperty( "plugin." + className, result );
93 getLog().info( "[MAVEN-CORE-IT-LOG] plugin: " + result );
94
95 try
96 {
97 Class type = coreRealm.loadClass( className );
98 result = getKey( type );
99 }
100 catch ( ClassNotFoundException e )
101 {
102 result = "";
103 }
104 properties.setProperty( "core." + className, result );
105 getLog().info( "[MAVEN-CORE-IT-LOG] core : " + result );
106 }
107 }
108
109 getLog().info( "[MAVEN-CORE-IT-LOG] Creating output file " + assigncompatPropertiesFile );
110
111 PropertiesUtil.write( assigncompatPropertiesFile, properties );
112
113 getLog().info( "[MAVEN-CORE-IT-LOG] Created output file " + assigncompatPropertiesFile );
114 }
115
116 private String getKey( Class type )
117 {
118 return type.hashCode() + "@" + type.getClassLoader().hashCode();
119 }
120
121 }