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 public class AssignmentCompatibleMojo
38 extends AbstractMojo
39 {
40
41
42
43
44
45
46 private File assigncompatPropertiesFile;
47
48
49
50
51
52
53 private String[] classNames;
54
55
56
57
58
59
60 public void execute()
61 throws MojoExecutionException
62 {
63 ClassLoader coreRealm = Mojo.class.getClassLoader();
64 ClassLoader pluginRealm = getClass().getClassLoader();
65
66 if ( coreRealm == pluginRealm )
67 {
68 throw new MojoExecutionException( "Unexpected class loader hierarchy, could not detect core realm" );
69 }
70
71 Properties properties = new Properties();
72
73 if ( classNames != null )
74 {
75 for ( String className : classNames )
76 {
77 String result;
78
79 getLog().info( "[MAVEN-CORE-IT-LOG] Loading class " + className );
80
81 try
82 {
83 Class type = pluginRealm.loadClass( className );
84 result = getKey( type );
85 }
86 catch ( ClassNotFoundException e )
87 {
88 result = "";
89 }
90 properties.setProperty( "plugin." + className, result );
91 getLog().info( "[MAVEN-CORE-IT-LOG] plugin: " + result );
92
93 try
94 {
95 Class type = coreRealm.loadClass( className );
96 result = getKey( type );
97 }
98 catch ( ClassNotFoundException e )
99 {
100 result = "";
101 }
102 properties.setProperty( "core." + className, result );
103 getLog().info( "[MAVEN-CORE-IT-LOG] core : " + result );
104 }
105 }
106
107 getLog().info( "[MAVEN-CORE-IT-LOG] Creating output file " + assigncompatPropertiesFile );
108
109 PropertiesUtil.write( assigncompatPropertiesFile, properties );
110
111 getLog().info( "[MAVEN-CORE-IT-LOG] Created output file " + assigncompatPropertiesFile );
112 }
113
114 private String getKey( Class type )
115 {
116 return type.hashCode() + "@" + type.getClassLoader().hashCode();
117 }
118
119 }