Skip to content

Commit 9c1657d

Browse files
committed
validate catalogItem.provider is present
Signed-off-by: Igor Fedorenko <[email protected]>
1 parent f9ba497 commit 9c1657d

File tree

3 files changed

+66
-3
lines changed

3 files changed

+66
-3
lines changed

org.sonatype.m2e.discovery.publisher.maven-plugin/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
<id>standard</id>
9999
<goals>
100100
<goal>java</goal>
101-
<goal>xpp3-reader</goal>
101+
<goal>xpp3-extended-reader</goal>
102102
<goal>xpp3-writer</goal>
103103
</goals>
104104
<configuration>

org.sonatype.m2e.discovery.publisher.maven-plugin/src/main/java/org/sonatype/m2e/discovery/publisher/M2eDiscoveryMetadataGeneratorMojo.java

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,11 @@
6767
import org.sonatype.m2e.discovery.catalog.model.DiscoveryCategory;
6868
import org.sonatype.m2e.discovery.catalog.model.DiscoveryIcon;
6969
import org.sonatype.m2e.discovery.catalog.model.IUData;
70+
import org.sonatype.m2e.discovery.catalog.model.InputLocation;
71+
import org.sonatype.m2e.discovery.catalog.model.InputLocationTracker;
7072
import org.sonatype.m2e.discovery.catalog.model.MavenData;
7173
import org.sonatype.m2e.discovery.catalog.model.P2Data;
72-
import org.sonatype.m2e.discovery.catalog.model.io.xpp3.DiscoveryCatalogModelXpp3Reader;
74+
import org.sonatype.m2e.discovery.catalog.model.io.xpp3.DiscoveryCatalogModelXpp3ReaderEx;
7375
import org.sonatype.m2e.discovery.publisher.p2.facade.P2Facade;
7476
import org.sonatype.tycho.equinox.EquinoxServiceFactory;
7577
import org.sonatype.tycho.p2.facade.internal.P2ApplicationLauncher;
@@ -149,6 +151,9 @@ public void execute()
149151
throw new RuntimeException( "Duplicate catalog item id " + catalogItem.getId() );
150152
}
151153

154+
getLog().debug( "Processing catalog item with id " + catalogItem.getId() );
155+
validateCatalogItem( catalog, catalogItem );
156+
152157
boolean hasLifecycleMappings = false;
153158
LifecycleMappingMetadataSource mergedLifecycleMappingMetadataSource =
154159
new LifecycleMappingMetadataSource();
@@ -275,6 +280,46 @@ else if ( mavenData != null )
275280
}
276281
}
277282

283+
private void validateCatalogItem( InputLocationTracker locationTracker, DiscoveryCatalogItem item )
284+
{
285+
List<String> messages = new ArrayList<String>();
286+
if ( nv( item.getId() ) == null )
287+
{
288+
messages.add( "id must be specified" );
289+
}
290+
if ( nv( item.getProvider() ) == null )
291+
{
292+
messages.add( "provider must be specified" );
293+
}
294+
295+
if ( !messages.isEmpty() )
296+
{
297+
StringBuilder sb = new StringBuilder();
298+
sb.append( "Problems with <catalogItem>" );
299+
300+
InputLocation location = item.getLocation( "" );
301+
if ( location != null )
302+
{
303+
sb.append( '[' ).append( location.toString() ).append( ']' );
304+
}
305+
306+
for ( String msg : messages )
307+
{
308+
sb.append( "\n " ).append( msg );
309+
}
310+
throw new RuntimeException( sb.toString() );
311+
}
312+
}
313+
314+
private static String nv( String str )
315+
{
316+
if ( str != null && !"".equals( str.trim() ) )
317+
{
318+
return str;
319+
}
320+
return null;
321+
}
322+
278323
private void generateP2RepositoryMetadata( File p2RepositoryDirectory )
279324
{
280325
List<String> contentArgs = new ArrayList<String>();
@@ -632,7 +677,7 @@ private DiscoveryCatalog loadDiscoveryCatalog()
632677
InputStream is = new FileInputStream( catalogFile );
633678
try
634679
{
635-
return new DiscoveryCatalogModelXpp3Reader().read( is );
680+
return new DiscoveryCatalogModelXpp3ReaderEx().read( is, true );
636681
}
637682
finally
638683
{

org.sonatype.m2e.discovery.publisher.maven-plugin/src/main/mdo/catalog.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,5 +228,23 @@
228228
</field>
229229
</fields>
230230
</class>
231+
232+
<class locationTracker="locations" java.clone="shallow">
233+
<name>InputLocation</name>
234+
<codeSegments>
235+
<codeSegment>
236+
<code>
237+
<![CDATA[
238+
239+
@Override
240+
public String toString()
241+
{
242+
return getLineNumber() + " : " + getColumnNumber();
243+
}
244+
]]>
245+
</code>
246+
</codeSegment>
247+
</codeSegments>
248+
</class>
231249
</classes>
232250
</model>

0 commit comments

Comments
 (0)