Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
maven-thrift-plugin
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
maven-thrift-plugin
Commits
ff27a62d
Commit
ff27a62d
authored
Feb 26, 2010
by
David Trott
Browse files
Options
Browse Files
Download
Plain Diff
Merge commit 'sergey/master'
parents
05a64e31
3e6cea0a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
198 additions
and
200 deletions
+198
-200
src/main/java/org/apache/thrift/maven/AbstractThriftMojo.java
...main/java/org/apache/thrift/maven/AbstractThriftMojo.java
+198
-200
No files found.
src/main/java/org/apache/thrift/maven/AbstractThriftMojo.java
View file @
ff27a62d
...
@@ -31,216 +31,214 @@ import java.util.jar.JarFile;
...
@@ -31,216 +31,214 @@ import java.util.jar.JarFile;
abstract
class
AbstractThriftMojo
extends
AbstractMojo
{
abstract
class
AbstractThriftMojo
extends
AbstractMojo
{
private
static
final
String
THRIFT_FILE_SUFFIX
=
".thrift"
;
private
static
final
String
THRIFT_FILE_SUFFIX
=
".thrift"
;
private
static
final
String
DEFAULT_INCLUDES
=
"**/*"
+
THRIFT_FILE_SUFFIX
;
private
static
final
String
DEFAULT_INCLUDES
=
"**/*"
+
THRIFT_FILE_SUFFIX
;
/**
/**
* The current Maven project.
* The current Maven project.
*
*
* @parameter default-value="${project}"
* @parameter default-value="${project}"
* @readonly
* @readonly
* @required
* @required
*/
*/
protected
MavenProject
project
;
protected
MavenProject
project
;
/**
/**
* A helper used to add resources to the project.
* A helper used to add resources to the project.
*
*
* @component
* @component
* @required
* @required
*/
*/
protected
MavenProjectHelper
projectHelper
;
protected
MavenProjectHelper
projectHelper
;
/**
/**
* This is the path to the {@code thrift} executable. By default it will
* This is the path to the {@code thrift} executable. By default it will search the {@code $PATH}.
* search the {@code $PATH}.
*
*
* @parameter default-value="thrift"
* @parameter default-value="thrift"
* @required
* @required
*/
*/
private
String
thriftExecutable
;
private
String
thriftExecutable
;
/**
/**
* @parameter
* @parameter
*/
*/
private
File
[]
additionalThriftPathElements
=
new
File
[]{};
private
File
[]
additionalThriftPathElements
=
new
File
[]{};
/**
/**
* Since {@code thrift} cannot access jars, thrift files in dependenceies are extracted to this location and deleted
* Since {@code thrift} cannot access jars, thrift files in dependenceies are
* on exit. This directory is always cleaned during execution.
* extracted to this location and deleted on exit. This directory is always
*
* cleaned during execution.
* @parameter expression="${java.io.tmpdir}/maven-thrift"
*
* @required
* @parameter expression="${java.io.tmpdir}/maven-thrift"
*/
* @required
private
File
temporaryThriftFileDirectory
;
*/
private
File
temporaryThriftFileDirectory
;
/**
* @parameter
/**
*/
*
private
Set
<
String
>
includes
=
ImmutableSet
.
of
(
DEFAULT_INCLUDES
);
* @parameter
*/
/**
private
Set
<
String
>
includes
=
ImmutableSet
.
of
(
DEFAULT_INCLUDES
);
* @parameter
*/
/**
private
Set
<
String
>
excludes
=
ImmutableSet
.
of
();
* @parameter
*/
private
Set
<
String
>
excludes
=
ImmutableSet
.
of
();
/**
/**
* Executes the mojo.
* Executes the mojo.
*/
*/
public
void
execute
()
throws
MojoExecutionException
,
MojoFailureException
{
public
void
execute
()
throws
MojoExecutionException
,
MojoFailureException
{
checkParameters
();
checkParameters
();
final
File
thriftSourceRoot
=
getThriftSourceRoot
();
final
File
thriftSourceRoot
=
getThriftSourceRoot
();
if
(
thriftSourceRoot
.
exists
())
{
if
(
thriftSourceRoot
.
exists
())
{
try
{
try
{
ImmutableSet
<
File
>
thriftFiles
=
ImmutableSet
<
File
>
thriftFiles
=
findThriftFilesInDirectory
(
thriftSourceRoot
);
findThriftFilesInDirectory
(
thriftSourceRoot
);
if
(
thriftFiles
.
isEmpty
())
{
if
(
thriftFiles
.
isEmpty
())
{
getLog
().
info
(
"No thrift files to compile."
);
getLog
().
info
(
"No thrift files to compile."
);
}
else
{
ImmutableSet
<
File
>
derivedThriftPathElements
=
makeThriftPathFromJars
(
temporaryThriftFileDirectory
,
getDependencyArtifactFiles
());
final
File
outputDirectory
=
getOutputDirectory
();
outputDirectory
.
mkdirs
();
// Quick fix to fix issues with two mvn installs in a row (ie no clean)
cleanDirectory
(
outputDirectory
);
Thrift
thrift
=
new
Thrift
.
Builder
(
thriftExecutable
,
outputDirectory
)
.
addThriftPathElement
(
thriftSourceRoot
)
.
addThriftPathElements
(
derivedThriftPathElements
)
.
addThriftPathElements
(
asList
(
additionalThriftPathElements
))
.
addThriftFiles
(
thriftFiles
)
.
build
();
final
int
exitStatus
=
thrift
.
compile
();
if
(
exitStatus
!=
0
)
{
throw
new
MojoFailureException
(
"Thrift did not exit cleanly. Review output for more information."
);
}
attachFiles
();
}
}
catch
(
IOException
e
)
{
throw
new
MojoExecutionException
(
"An IO error occured"
,
e
);
}
catch
(
IllegalArgumentException
e
)
{
throw
new
MojoFailureException
(
"Thrift failed to execute because: "
+
e
.
getMessage
(),
e
);
}
catch
(
CommandLineException
e
)
{
throw
new
MojoExecutionException
(
"An error occured while invoking thrift."
,
e
);
}
}
else
{
}
else
{
ImmutableSet
<
File
>
derivedThriftPathElements
=
getLog
()
makeThriftPathFromJars
(
.
info
(
temporaryThriftFileDirectory
,
getDependencyArtifactFiles
());
format
(
final
File
outputDirectory
=
getOutputDirectory
();
"%s does not exist. Review the configuration or consider disabling the plugin."
,
outputDirectory
.
mkdirs
();
thriftSourceRoot
));
// Quick fix to fix issues with two mvn installs in a row (ie no clean)
cleanDirectory
(
outputDirectory
);
Thrift
thrift
=
new
Thrift
.
Builder
(
thriftExecutable
,
outputDirectory
)
.
addThriftPathElement
(
thriftSourceRoot
)
.
addThriftPathElements
(
derivedThriftPathElements
)
.
addThriftPathElements
(
asList
(
additionalThriftPathElements
))
.
addThriftFiles
(
thriftFiles
)
.
build
();
final
int
exitStatus
=
thrift
.
compile
();
if
(
exitStatus
!=
0
)
{
throw
new
MojoFailureException
(
"Thrift did not exit cleanly. Review output for more information."
);
}
attachFiles
();
}
}
}
catch
(
IOException
e
)
{
throw
new
MojoExecutionException
(
"An IO error occured"
,
e
);
}
catch
(
IllegalArgumentException
e
)
{
throw
new
MojoFailureException
(
"Thrift failed to execute because: "
+
e
.
getMessage
(),
e
);
}
catch
(
CommandLineException
e
)
{
throw
new
MojoExecutionException
(
"An error occured while invoking thrift."
,
e
);
}
}
else
{
getLog
()
.
info
(
format
(
"%s does not exist. Review the configuration or consider disabling the plugin."
,
thriftSourceRoot
));
}
}
}
private
void
checkParameters
()
{
private
void
checkParameters
()
{
checkNotNull
(
project
,
"project"
);
checkNotNull
(
project
,
"project"
);
checkNotNull
(
projectHelper
,
"projectHelper"
);
checkNotNull
(
projectHelper
,
"projectHelper"
);
checkNotNull
(
thriftExecutable
,
"thriftExecutable"
);
checkNotNull
(
thriftExecutable
,
"thriftExecutable"
);
final
File
thriftSourceRoot
=
getThriftSourceRoot
();
final
File
thriftSourceRoot
=
getThriftSourceRoot
();
checkNotNull
(
thriftSourceRoot
);
checkNotNull
(
thriftSourceRoot
);
checkArgument
(!
thriftSourceRoot
.
isFile
(),
checkArgument
(!
thriftSourceRoot
.
isFile
(),
"thriftSourceRoot is a file, not a diretory"
);
"thriftSourceRoot is a file, not a diretory"
);
checkNotNull
(
temporaryThriftFileDirectory
,
"temporaryThriftFileDirectory"
);
checkNotNull
(
temporaryThriftFileDirectory
,
"temporaryThriftFileDirectory"
);
checkState
(!
temporaryThriftFileDirectory
.
isFile
(),
checkState
(!
temporaryThriftFileDirectory
.
isFile
(),
"temporaryThriftFileDirectory is a file, not a directory"
);
"temporaryThriftFileDirectory is a file, not a directory"
);
final
File
outputDirectory
=
getOutputDirectory
();
final
File
outputDirectory
=
getOutputDirectory
();
checkNotNull
(
outputDirectory
);
checkNotNull
(
outputDirectory
);
checkState
(!
outputDirectory
.
isFile
(),
checkState
(!
outputDirectory
.
isFile
(),
"the outputDirectory is a file, not a directory"
);
"the outputDirectory is a file, not a directory"
);
}
protected
abstract
File
getThriftSourceRoot
();
protected
abstract
List
<
Artifact
>
getDependencyArtifacts
();
protected
abstract
File
getOutputDirectory
();
protected
abstract
void
attachFiles
();
/**
* Gets the {@link File} for each dependency artifact.
*
* @return A set of all dependency artifacts.
*/
private
ImmutableSet
<
File
>
getDependencyArtifactFiles
()
{
Set
<
File
>
dependencyArtifactFiles
=
newHashSet
();
for
(
Artifact
artifact
:
getDependencyArtifacts
())
{
dependencyArtifactFiles
.
add
(
artifact
.
getFile
());
}
}
return
ImmutableSet
.
copyOf
(
dependencyArtifactFiles
);
}
protected
abstract
File
getThriftSourceRoot
();
/**
protected
abstract
List
<
Artifact
>
getDependencyArtifacts
();
*
* @throws IOException
protected
abstract
File
getOutputDirectory
();
*/
ImmutableSet
<
File
>
makeThriftPathFromJars
(
protected
abstract
void
attachFiles
();
File
temporaryThriftFileDirectory
,
Iterable
<
File
>
classpathElementFiles
)
throws
IOException
{
/**
checkNotNull
(
classpathElementFiles
,
"classpathElementFiles"
);
* Gets the {@link File} for each dependency artifact.
// clean the temporary directory to ensure that stale files aren't used
*
if
(
temporaryThriftFileDirectory
.
exists
())
{
* @return A set of all dependency artifacts.
cleanDirectory
(
temporaryThriftFileDirectory
);
*/
private
ImmutableSet
<
File
>
getDependencyArtifactFiles
()
{
Set
<
File
>
dependencyArtifactFiles
=
newHashSet
();
for
(
Artifact
artifact
:
getDependencyArtifacts
())
{
dependencyArtifactFiles
.
add
(
artifact
.
getFile
());
}
return
ImmutableSet
.
copyOf
(
dependencyArtifactFiles
);
}
}
Set
<
File
>
thriftDirectories
=
newHashSet
();
for
(
File
classpathElementFile
:
classpathElementFiles
)
{
/**
checkArgument
(
classpathElementFile
.
isFile
(),
"%s is not a file"
,
* @throws IOException
classpathElementFile
);
*/
// create the jar file. the constructor validates.
ImmutableSet
<
File
>
makeThriftPathFromJars
(
JarFile
classpathJar
=
null
;
File
temporaryThriftFileDirectory
,
Iterable
<
File
>
classpathElementFiles
)
try
{
throws
IOException
{
classpathJar
=
new
JarFile
(
classpathElementFile
);
checkNotNull
(
classpathElementFiles
,
"classpathElementFiles"
);
}
catch
(
IOException
e
)
{
// clean the temporary directory to ensure that stale files aren't used
throw
new
IllegalArgumentException
(
format
(
if
(
temporaryThriftFileDirectory
.
exists
())
{
"%s was not a readable artifact"
,
classpathElementFile
));
cleanDirectory
(
temporaryThriftFileDirectory
);
}
for
(
JarEntry
jarEntry
:
list
(
classpathJar
.
entries
()))
{
final
String
jarEntryName
=
jarEntry
.
getName
();
if
(
jarEntry
.
getName
().
endsWith
(
THRIFT_FILE_SUFFIX
))
{
final
File
uncompressedCopy
=
new
File
(
new
File
(
temporaryThriftFileDirectory
,
classpathJar
.
getName
()),
jarEntryName
);
uncompressedCopy
.
getParentFile
().
mkdirs
();
copyStreamToFile
(
new
RawInputStreamFacade
(
classpathJar
.
getInputStream
(
jarEntry
)),
uncompressedCopy
);
thriftDirectories
.
add
(
uncompressedCopy
.
getParentFile
());
}
}
}
Set
<
File
>
thriftDirectories
=
newHashSet
();
for
(
File
classpathElementFile
:
classpathElementFiles
)
{
checkArgument
(
classpathElementFile
.
isFile
(),
"%s is not a file"
,
classpathElementFile
);
// create the jar file. the constructor validates.
JarFile
classpathJar
=
null
;
try
{
classpathJar
=
new
JarFile
(
classpathElementFile
);
}
catch
(
IOException
e
)
{
throw
new
IllegalArgumentException
(
format
(
"%s was not a readable artifact"
,
classpathElementFile
));
}
for
(
JarEntry
jarEntry
:
list
(
classpathJar
.
entries
()))
{
final
String
jarEntryName
=
jarEntry
.
getName
();
if
(
jarEntry
.
getName
().
endsWith
(
THRIFT_FILE_SUFFIX
))
{
//replace logic is used in order to fix issue of an invalid windows classpath to the thrift file
// inside a jar.
final
File
uncompressedCopy
=
new
File
(
new
File
(
temporaryThriftFileDirectory
,
classpathJar
.
getName
().
replace
(
":"
,
"_"
)),
jarEntryName
);
uncompressedCopy
.
getParentFile
().
mkdirs
();
copyStreamToFile
(
new
RawInputStreamFacade
(
classpathJar
.
getInputStream
(
jarEntry
)),
uncompressedCopy
);
thriftDirectories
.
add
(
uncompressedCopy
.
getParentFile
());
}
}
}
forceDeleteOnExit
(
temporaryThriftFileDirectory
);
return
ImmutableSet
.
copyOf
(
thriftDirectories
);
}
}
forceDeleteOnExit
(
temporaryThriftFileDirectory
);
return
ImmutableSet
.
copyOf
(
thriftDirectories
);
ImmutableSet
<
File
>
findThriftFilesInDirectory
(
File
directory
)
}
throws
IOException
{
checkNotNull
(
directory
);
ImmutableSet
<
File
>
findThriftFilesInDirectory
(
File
directory
)
checkArgument
(
directory
.
isDirectory
(),
"%s is not a directory"
,
directory
);
throws
IOException
{
// TODO(gak): plexus-utils needs generics
checkNotNull
(
directory
);
@SuppressWarnings
(
"unchecked"
)
checkArgument
(
directory
.
isDirectory
(),
"%s is not a directory"
,
directory
);
List
<
File
>
thriftFilesInDirectory
=
// TODO(gak): plexus-utils needs generics
getFiles
(
directory
,
join
(
","
,
includes
),
join
(
","
,
excludes
));
@SuppressWarnings
(
"unchecked"
)
return
ImmutableSet
.
copyOf
(
thriftFilesInDirectory
);
List
<
File
>
thriftFilesInDirectory
=
}
getFiles
(
directory
,
join
(
","
,
includes
),
join
(
","
,
excludes
));
return
ImmutableSet
.
copyOf
(
thriftFilesInDirectory
);
ImmutableSet
<
File
>
findThriftFilesInDirectories
(
}
Iterable
<
File
>
directories
)
throws
IOException
{
checkNotNull
(
directories
);
ImmutableSet
<
File
>
findThriftFilesInDirectories
(
Set
<
File
>
thriftFiles
=
newHashSet
();
Iterable
<
File
>
directories
)
throws
IOException
{
for
(
File
directory
:
directories
)
{
checkNotNull
(
directories
);
thriftFiles
.
addAll
(
findThriftFilesInDirectory
(
directory
));
Set
<
File
>
thriftFiles
=
newHashSet
();
}
for
(
File
directory
:
directories
)
{
return
ImmutableSet
.
copyOf
(
thriftFiles
);
thriftFiles
.
addAll
(
findThriftFilesInDirectory
(
directory
));
}
}
return
ImmutableSet
.
copyOf
(
thriftFiles
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment