Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
Bug 1098295 - Saving Project Through GUI Overwrites POM
Browse files Browse the repository at this point in the history
(cherry picked from commit 080e9e0)
  • Loading branch information
Rikkola committed Jan 2, 2015
1 parent dc34233 commit 28a6ddc
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ public class RepositoryStructureServiceImpl
@Inject
private MetadataService metadataService;

// @Inject
// private ValidationService validationService;

@Inject
private GuvnorM2Repository m2service;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,13 @@ private String toString(POM pom,
model.addRepository(fromClientModelToPom(repository));
}
} else { // If it is a kjar
model.setPackaging(PACKAGING);

if(isPackagingSet(model)){
// Currently we only support multimodules and kjars.
// But since the user can change and customers have actually changed the packaging to jar
// we do not overwrite the setting.
model.setPackaging(PACKAGING);
}
if (pom.getParent() != null) {
Parent parent = new Parent();
parent.setGroupId(pom.getParent().getGroupId());
Expand Down Expand Up @@ -111,6 +117,10 @@ private String toString(POM pom,
return stringWriter.toString();
}

private boolean isPackagingSet(Model model) {

This comment has been minimized.

Copy link
@triceo

triceo Jan 2, 2015

Based on what it actually returns, should't this method be called isPackagingNotSet(Model model)?

This comment has been minimized.

Copy link
@Rikkola

Rikkola Jan 4, 2015

Author Member

You are right. It is a trap now. Thanks for noticing, I'll fix that.

return model.getPackaging() == null || model.getPackaging().isEmpty();
}

/**
* @param gavModel The model that is saved
* @param originalPomAsText The original pom in text form, since the guvnor POM model does not cover all the pom.xml features.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import javax.inject.Inject;
import javax.inject.Named;

import org.guvnor.common.services.backend.config.SafeSessionInfo;
import org.guvnor.common.services.backend.exceptions.ExceptionUtilities;
import org.guvnor.common.services.project.model.POM;
import org.guvnor.common.services.project.model.Repository;
Expand All @@ -22,7 +21,6 @@
import org.uberfire.io.IOService;
import org.uberfire.java.nio.file.FileAlreadyExistsException;
import org.uberfire.java.nio.file.FileSystem;
import org.uberfire.rpc.SessionInfo;

@Service
@ApplicationScoped
Expand All @@ -37,8 +35,6 @@ public class POMServiceImpl
@Inject
private CommentedOptionFactory optionsFactory;

private SessionInfo sessionInfo;

public POMServiceImpl() {
// For Weld
}
Expand All @@ -47,13 +43,11 @@ public POMServiceImpl() {
public POMServiceImpl( final @Named("ioStrategy") IOService ioService,
final POMContentHandler pomContentHandler,
final M2RepoService m2RepoService,
final MetadataService metadataService,
final SessionInfo sessionInfo ) {
final MetadataService metadataService ) {
this.ioService = ioService;
this.pomContentHandler = pomContentHandler;
this.m2RepoService = m2RepoService;
this.metadataService = metadataService;
this.sessionInfo = new SafeSessionInfo(sessionInfo);
}

@Override
Expand Down Expand Up @@ -120,14 +114,6 @@ public Path save( final Path path,
metadata ) );
}

//The pom.xml, kmodule.xml and project.imports are all saved from ProjectScreenPresenter
//We only raise InvalidateDMOProjectCacheEvent and ResourceUpdatedEvent(pom.xml) events once
//to avoid duplicating events (and re-construction of DMO).

//@wmedvede now the InvalidateDMOProjectCacheEvent will be fired in the DataModelResourceChangeObserver
//Invalidate Project-level DMO cache as POM has changed.
//invalidateDMOProjectCache.fire( new InvalidateDMOProjectCacheEvent( path ) );

return path;

} catch ( Exception e ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,31 @@ public void testPOMContentHandlerExistingProject() throws IOException, XmlPullPa
assertContainsIgnoreWhitespace( PLUGIN_XML,
enrichedXml );
}
@Test
public void testPOMContentHandlerExistingJarProject() throws IOException, XmlPullParserException {
/*
Keep the original type
*/

final POMContentHandler handler = new POMContentHandler();
final String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<project xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\" xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"
+ "<modelVersion>4.0.0</modelVersion>"
+ "<groupId>org.guvnor</groupId>"
+ "<artifactId>test</artifactId>"
+ "<version>0.0.1</version>"
+ "<packaging>something</packaging>"
+ "<name>name</name>"
+ "<description>description</description>"
+ "</project>";

final String enrichedXml = handler.toString( handler.toModel( xml ),
xml );


assertContainsIgnoreWhitespace( "<packaging>something</packaging>",
enrichedXml );
}

@Test
public void testPOMContentHandlerExistingKieProject() throws IOException, XmlPullParserException {
Expand Down Expand Up @@ -188,10 +213,10 @@ public void testParent() throws Exception {
}

private void assertContainsIgnoreWhitespace( final String expected,
final String actual ) {
final String xml ) {
final String cleanExpected = expected.replaceAll( "\\s+",
"" );
final String cleanActual = actual.replaceAll( "\\s+",
final String cleanActual = xml.replaceAll( "\\s+",
"" );

assertTrue( cleanActual.contains( cleanExpected ) );
Expand Down

0 comments on commit 28a6ddc

Please sign in to comment.