Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
xwiki-platform
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
XWiki
xwiki-platform
Commits
bccbcff2
Commit
bccbcff2
authored
10 years ago
by
tmortagne
Browse files
Options
Downloads
Patches
Plain Diff
[misc] Revert change committed by mistake
parent
829e2837
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
xwiki-platform-tools/xwiki-platform-tool-packager-plugin/src/main/java/com/xpn/xwiki/tool/backup/ImportMojo.java
+134
-7
134 additions, 7 deletions
...n/src/main/java/com/xpn/xwiki/tool/backup/ImportMojo.java
with
134 additions
and
7 deletions
xwiki-platform-tools/xwiki-platform-tool-packager-plugin/src/main/java/com/xpn/xwiki/tool/backup/ImportMojo.java
+
134
−
7
View file @
bccbcff2
...
@@ -20,29 +20,48 @@
...
@@ -20,29 +20,48 @@
package
com.xpn.xwiki.tool.backup
;
package
com.xpn.xwiki.tool.backup
;
import
java.io.File
;
import
java.io.File
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.List
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.maven.artifact.Artifact
;
import
org.apache.maven.artifact.Artifact
;
import
org.apache.maven.execution.MavenSession
;
import
org.apache.maven.model.Dependency
;
import
org.apache.maven.model.Developer
;
import
org.apache.maven.model.License
;
import
org.apache.maven.model.Model
;
import
org.apache.maven.model.building.ModelBuildingRequest
;
import
org.apache.maven.plugin.AbstractMojo
;
import
org.apache.maven.plugin.AbstractMojo
;
import
org.apache.maven.plugin.MojoExecutionException
;
import
org.apache.maven.plugin.MojoExecutionException
;
import
org.apache.maven.plugin.MojoFailureException
;
import
org.apache.maven.plugin.MojoFailureException
;
import
org.apache.maven.project.DefaultProjectBuildingRequest
;
import
org.apache.maven.project.MavenProject
;
import
org.apache.maven.project.MavenProject
;
import
org.apache.maven.project.ProjectBuilder
;
import
org.apache.maven.project.ProjectBuilder
;
import
org.apache.maven.project.ProjectBuildingException
;
import
org.apache.maven.project.ProjectBuildingRequest
;
import
org.apache.maven.project.ProjectBuildingResult
;
import
org.apache.maven.repository.RepositorySystem
;
import
org.apache.maven.repository.RepositorySystem
;
import
org.hibernate.cfg.Environment
;
import
org.xwiki.component.manager.ComponentLookupException
;
import
org.xwiki.component.manager.ComponentLookupException
;
import
org.xwiki.component.manager.ComponentManager
;
import
org.xwiki.component.manager.ComponentManager
;
import
org.xwiki.extension.Extension
;
import
org.xwiki.extension.DefaultExtensionAuthor
;
import
org.xwiki.extension.DefaultExtensionDependency
;
import
org.xwiki.extension.ExtensionId
;
import
org.xwiki.extension.ExtensionLicense
;
import
org.xwiki.extension.ExtensionLicenseManager
;
import
org.xwiki.extension.InstallException
;
import
org.xwiki.extension.InstallException
;
import
org.xwiki.extension.LocalExtension
;
import
org.xwiki.extension.LocalExtension
;
import
org.xwiki.extension.repository.InstalledExtensionRepository
;
import
org.xwiki.extension.repository.InstalledExtensionRepository
;
import
org.xwiki.extension.repository.LocalExtensionRepository
;
import
org.xwiki.extension.repository.LocalExtensionRepository
;
import
org.xwiki.extension.repository.LocalExtensionRepositoryException
;
import
org.xwiki.extension.repository.LocalExtensionRepositoryException
;
import
org.xwiki.extension.repository.internal.local.DefaultLocalExtension
;
import
org.xwiki.extension.repository.internal.local.DefaultLocalExtension
;
import
org.xwiki.extension.version.internal.DefaultVersionConstraint
;
import
org.xwiki.properties.ConverterManager
;
import
org.xwiki.properties.ConverterManager
;
import
org.xwiki.tool.utils.LogUtils
;
import
org.xwiki.tool.utils.LogUtils
;
import
org.hibernate.cfg.Environment
;
import
com.xpn.xwiki.XWikiContext
;
import
com.xpn.xwiki.XWikiContext
;
...
@@ -116,6 +135,14 @@ public class ImportMojo extends AbstractMojo
...
@@ -116,6 +135,14 @@ public class ImportMojo extends AbstractMojo
*/
*/
protected
RepositorySystem
repositorySystem
;
protected
RepositorySystem
repositorySystem
;
/**
* The current Maven session being executed.
*
* @parameter default-value="${session}"
* @readonly
*/
private
MavenSession
session
;
@Override
@Override
public
void
execute
()
throws
MojoExecutionException
,
MojoFailureException
public
void
execute
()
throws
MojoExecutionException
,
MojoFailureException
{
{
...
@@ -185,7 +212,7 @@ private void importDependencies(Importer importer, String databaseName, File hib
...
@@ -185,7 +212,7 @@ private void importDependencies(Importer importer, String databaseName, File hib
}
}
private
void
installExtension
(
Artifact
artifact
,
XWikiContext
xcontext
)
throws
ComponentLookupException
,
private
void
installExtension
(
Artifact
artifact
,
XWikiContext
xcontext
)
throws
ComponentLookupException
,
InstallException
,
LocalExtensionRepositoryException
InstallException
,
LocalExtensionRepositoryException
,
MojoExecutionException
{
{
ComponentManager
componentManager
=
(
ComponentManager
)
xcontext
.
get
(
ComponentManager
.
class
.
getName
());
ComponentManager
componentManager
=
(
ComponentManager
)
xcontext
.
get
(
ComponentManager
.
class
.
getName
());
...
@@ -194,14 +221,114 @@ private void installExtension(Artifact artifact, XWikiContext xcontext) throws C
...
@@ -194,14 +221,114 @@ private void installExtension(Artifact artifact, XWikiContext xcontext) throws C
InstalledExtensionRepository
installedExtensionRepository
=
InstalledExtensionRepository
installedExtensionRepository
=
componentManager
.
getInstance
(
InstalledExtensionRepository
.
class
);
componentManager
.
getInstance
(
InstalledExtensionRepository
.
class
);
ConverterManager
converter
=
componentManager
.
getInstance
(
ConverterManager
.
class
);
DefaultLocalExtension
extension
=
Extension
mavenExtension
=
converter
.
convert
(
Extension
.
class
,
this
.
project
.
getModel
());
new
DefaultLocalExtension
(
null
,
new
ExtensionId
(
artifact
.
getGroupId
()
+
':'
+
artifact
.
getArtifactId
(),
artifact
.
getBaseVersion
()),
artifact
.
getType
());
DefaultLocalExtension
extension
=
new
DefaultLocalExtension
(
null
,
mavenExtension
);
extension
.
setFile
(
artifact
.
getFile
());
extension
.
setFile
(
artifact
.
getFile
());
MavenProject
project
=
getMavenProject
(
artifact
);
toExtension
(
extension
,
project
.
getModel
(),
componentManager
);
LocalExtension
localExtension
=
localExtensionRepository
.
storeExtension
(
extension
);
LocalExtension
localExtension
=
localExtensionRepository
.
storeExtension
(
extension
);
installedExtensionRepository
.
installExtension
(
localExtension
,
"wiki:xwiki"
,
true
);
installedExtensionRepository
.
installExtension
(
localExtension
,
"wiki:xwiki"
,
true
);
}
}
// Maven -> Extension
// TODO: put all this, what's on core extension scanner and maven repository handler in a commons module
private
void
toExtension
(
DefaultLocalExtension
extension
,
Model
model
,
ComponentManager
componentManager
)
throws
ComponentLookupException
{
extension
.
setName
(
getPropertyString
(
model
,
MPNAME_NAME
,
model
.
getName
()));
extension
.
setSummary
(
getPropertyString
(
model
,
MPNAME_SUMMARY
,
model
.
getDescription
()));
extension
.
setWebsite
(
getPropertyString
(
model
,
MPNAME_WEBSITE
,
model
.
getUrl
()));
// authors
for
(
Developer
developer
:
model
.
getDevelopers
())
{
URL
authorURL
=
null
;
if
(
developer
.
getUrl
()
!=
null
)
{
try
{
authorURL
=
new
URL
(
developer
.
getUrl
());
}
catch
(
MalformedURLException
e
)
{
// TODO: log ?
}
}
extension
.
addAuthor
(
new
DefaultExtensionAuthor
(
StringUtils
.
defaultIfBlank
(
developer
.
getName
(),
developer
.
getId
()),
authorURL
));
}
// licenses
if
(!
model
.
getLicenses
().
isEmpty
())
{
ExtensionLicenseManager
licenseManager
=
componentManager
.
getInstance
(
ExtensionLicenseManager
.
class
);
for
(
License
license
:
model
.
getLicenses
())
{
extension
.
addLicense
(
getExtensionLicense
(
license
,
licenseManager
));
}
}
// features
String
featuresString
=
getProperty
(
model
,
MPNAME_FEATURES
);
if
(
StringUtils
.
isNotBlank
(
featuresString
))
{
featuresString
=
featuresString
.
replaceAll
(
"[\r\n]"
,
""
);
ConverterManager
converter
=
componentManager
.
getInstance
(
ConverterManager
.
class
);
extension
.
setFeatures
(
converter
.<
Collection
<
String
>>
convert
(
List
.
class
,
featuresString
));
}
// dependencies
for
(
Dependency
mavenDependency
:
model
.
getDependencies
())
{
if
(!
mavenDependency
.
isOptional
()
&&
(
mavenDependency
.
getScope
().
equals
(
"compile"
)
||
mavenDependency
.
getScope
().
equals
(
"runtime"
)))
{
extension
.
addDependency
(
new
DefaultExtensionDependency
(
mavenDependency
.
getGroupId
()
+
':'
+
mavenDependency
.
getArtifactId
(),
new
DefaultVersionConstraint
(
mavenDependency
.
getVersion
())));
}
}
}
private
MavenProject
getMavenProject
(
Artifact
artifact
)
throws
MojoExecutionException
{
try
{
ProjectBuildingRequest
request
=
new
DefaultProjectBuildingRequest
(
this
.
session
.
getProjectBuildingRequest
())
// We don't want to execute any plugin here
.
setProcessPlugins
(
false
)
// It's not this plugin job to validate this pom.xml
.
setValidationLevel
(
ModelBuildingRequest
.
VALIDATION_LEVEL_MINIMAL
)
// Use the repositories configured for the built project instead of the default Maven ones
.
setRemoteRepositories
(
this
.
session
.
getCurrentProject
().
getRemoteArtifactRepositories
());
// Note: build() will automatically get the POM artifact corresponding to the passed artifact.
ProjectBuildingResult
result
=
this
.
projectBuilder
.
build
(
artifact
,
request
);
return
result
.
getProject
();
}
catch
(
ProjectBuildingException
e
)
{
throw
new
MojoExecutionException
(
String
.
format
(
"Failed to build project for [%s]"
,
artifact
),
e
);
}
}
private
String
getProperty
(
Model
model
,
String
propertyName
)
{
return
model
.
getProperties
().
getProperty
(
MPKEYPREFIX
+
propertyName
);
}
private
String
getPropertyString
(
Model
model
,
String
propertyName
,
String
def
)
{
return
StringUtils
.
defaultString
(
getProperty
(
model
,
propertyName
),
def
);
}
// TODO: download custom licenses content
private
ExtensionLicense
getExtensionLicense
(
License
license
,
ExtensionLicenseManager
licenseManager
)
{
if
(
license
.
getName
()
==
null
)
{
return
new
ExtensionLicense
(
"noname"
,
null
);
}
return
createLicenseByName
(
license
.
getName
(),
licenseManager
);
}
private
ExtensionLicense
createLicenseByName
(
String
name
,
ExtensionLicenseManager
licenseManager
)
{
ExtensionLicense
extensionLicense
=
licenseManager
.
getLicense
(
name
);
return
extensionLicense
!=
null
?
extensionLicense
:
new
ExtensionLicense
(
name
,
null
);
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment