Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maven conversion #9

Merged
merged 22 commits into from
Jun 30, 2016
Merged

Maven conversion #9

merged 22 commits into from
Jun 30, 2016

Conversation

claudiow
Copy link
Contributor

I just checked in the initial work

It stills is in a pretty untidy state, as I only converted the demo and log4jna projects to Maven and made them fully log4j 2 compliant. I still have to do more clean up.

Done so far:
Replaced all dependencies on log4j2 and jna with latest versions from Maven Central in the pom.xml
Replaced some deprecated methods with the recommended replacement.
Updated the projects to Java 8.
Added the dll as a resource to avoid copying or building it to run the tests or the demo application.
Locally I can use the dll as a Maven dependency from my internal Nexus repository.

Some Ideas:
Extract the dll build to its own sub project and keep a minimal ant build for it
Replace the ant build for a full fledged Maven build with a parent project.
Deprecate and eliminate the thirdparty sub project as all dependencies now come from Maven Central.
Distribute the dll from Maven Central for end users.
Create a Maven site with all the documentation on how to use and how to collaborate with the project.

@@ -185,7 +181,7 @@ public void activateOptions() {
registerEventSource();
}

@Override
//@Override
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete this, don't comment out.

@dblock
Copy link
Owner

dblock commented Jun 21, 2016

First, excellent work. Thanks. I really want this in, so lets work through the remaining items.

I think you're spot on of what's next. I would merge this as soon as the top of the build works with maven, so build.cmd and thirdparty dependencies get removed. Want to finish it up?

@claudiow
Copy link
Contributor Author

Thanks.

The parent project is under way. I can try to complete the list by the end of this week.

Is there a we server where to publish a maven site or should we modify the top readme.md file with instructions on how to use teh jar and run the demo?

I'll let you know when the parent project is ready and the clean up completed.

@dblock
Copy link
Owner

dblock commented Jun 21, 2016

We've never published log4jna into maven central, #6 has been open for a while. Would appreciate your help with getting that setup, but that doesn't have to happen in the same PR, feel free to do it next. Definitely modify README. Whatever keeps the project in a consistent state.

@dblock
Copy link
Owner

dblock commented Jun 21, 2016

After we get this merged I'll want you to join the maintainers list, so you can make the first maven release if you're interested ;)

@claudiow
Copy link
Contributor Author

I think I can do the deployment,
It will take some manual work and experimentation, above all because of the requirement of having all the files signed with pgp.
Right now I have some free time, between contracts, but if something comes my way my velocity will be impacted.

@claudiow
Copy link
Contributor Author

On another note I'm very tempted to delete the "System.err(...)" lines from the code, they pollute the console and it looks that was place there for some debugging that is not necessary any more.

@claudiow
Copy link
Contributor Author

After thought:
Will the org.apache packaging be a problem to distribute in maven central?

@dblock
Copy link
Owner

dblock commented Jun 22, 2016

I don't think org.apache will be a problem, but if it is we can change the namespace.

@claudiow
Copy link
Contributor Author

claudiow commented Jun 22, 2016

I have been doing some reading about how to publish to Maven Central.

Only ASF projects can publish directly to it.

Other open source projects must use a staging repository and do a promotion to central.

The usual way to do it is to open an account with Sonatype's Nexus OSSRH and promote from there.
See http://central.sonatype.org/pages/apache-maven.html.

We have to open a Jira account for the top level coordinates for the project org.<whatever> in order to access OSSRH repositories.

I don't think that the package org.apache is going to be a problem, but the POM coordinate should be something different such as org.log4jna very mush like JNA package is com.sun... but the project is net.java.dev.jna.

That way we will be able to differentiate log4jna from other ASF projects.

Using the dependencies will look like this in a pom.xml

    <dependency>
        <groupId>org.log4jna</groupId>
        <artifactId>log4jna</artifactId>
        <version>2.0</version>
    </dependency>

@dblock
Copy link
Owner

dblock commented Jun 23, 2016

I'm down with anything, but lets focus on first steps, getting this thing to build and work with maven all the way?

@claudiow
Copy link
Contributor Author

claudiow commented Jun 24, 2016

I think we are ready to test the build.
checkout the branch and on the parent project run

mvn clean site javaoc:jar source:jar package

You will get all the jars in each project plus the dll in the new win32dll separated project,

In the assembly project you will find a distributable zip file with all the documentation and the jars and dll in the /lib directory

The documentation stills is work in progress, I want to replace it with the maven site and update the *.md files to reflect the changes.

I renamed the location of log4jna to log4jna-api to allow for a top level log4jna with documentation for all the project.

I did not changed the project layout in git just used the name in the pom to rename the api jar.

@dblock
Copy link
Owner

dblock commented Jun 25, 2016

I don't see a pom.xml or anything like that at the root and there's still a build.xml. I tried running mvn from a few places (like demo) and none have worked for me with different failures.

@claudiow
Copy link
Contributor Author

claudiow commented Jun 25, 2016

Did you try to run it on the parent project using mvn clean site javadoc:jar sources:jar package?

There is no intention of having a pom.xml on the root of the repository, I'm using the concept of parent project and relative sub projects.

The root of the repository becomes a place for readme and instructions on github documentation format, but is not part of the build. I can change this if you want.

DO the errors refer to repositories or distribution management problems?

@claudiow
Copy link
Contributor Author

claudiow commented Jun 25, 2016

On another topic, I started the procedure to get access to Sonatypet and Maven Central.

See this:

https://issues.sonatype.org/browse/OSSRH-23287?focusedCommentId=362563&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-362563

I think that we should go with .org.dbloock unless you want to migrate everything including the github repository to org.log4jna but we need to register the domain first.

@dblock
Copy link
Owner

dblock commented Jun 26, 2016

Lets back up just a little and not get side tracked by future tasks and try to finish this PR ;)

First, we want a build from "the top". Maybe that means modifying build.cmd, which is fine. Make it "super easy" for a new developer to build the project like it's now. Remove any ant things. I don't want to type that crazy command every time from some subdirectory.

Look at https://github.com/dblock/oshi, that team has done a great job with mavenizing it.

@claudiow
Copy link
Contributor Author

claudiow commented Jun 26, 2016

That's easy to do, all I have to do is to move parent to the top and delete parent.

Thinking on having a repository where to deploy the SNAPSHOT buil is not much about side tracking as it is about testing how the deploy command in mvn works.

In my mind with library projects, Maven final objective is to deploy to its repositories.

@claudiow
Copy link
Contributor Author

Done,

To build running the tests the registry entries HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\Application\Log4jnaTest and HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\Win32LogApplication\WinLogger with the CategoryCount and TypesSupported entries are required.

Run mvn clean site package in the root to see a local build use skip test if the registry entries do not exist

If you have errors, please provide a sample, I checked out the project in a clean machine and found no problems with the build.

@dblock
Copy link
Owner

dblock commented Jun 27, 2016

Making progress! Failed for me with this:

[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 1 source file to C:\Users\dblock\source\log4jna\dblock\log4jna-api\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Log4JNA Parent .................................... SUCCESS [1:11.746s]
[INFO] Log4JNA Api ....................................... FAILURE [22.860s]
[INFO] Log4JNA Assembly .................................. SKIPPED
[INFO] Log4JNA Demo ...................................... SKIPPED
[INFO] Log4JNA Win32dll .................................. SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:35.406s
[INFO] Finished at: Mon Jun 27 03:43:03 EDT 2016
[INFO] Final Memory: 27M/76M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.3:compile (default-compile) on project log4jna-api: Fatal error compiling: invalid target release: 1.8 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :log4jna-api

Also:

  • Needs a 1-liner in CHANGELOG for mavenizing the build.
  • Is there a way to have a default maven target for the above so I can just do mvn?

@dblock
Copy link
Owner

dblock commented Jun 27, 2016

I don't remember needing to do anything by hand to get tests to pass - is this something new or maybe you just need to be admin to run the build since those registry keys can't otherwise be created?

@claudiow
Copy link
Contributor Author

Do you have Java 8 installed? The build requires Java 8.

Yes the registry requirement is because of the elevated privileges to write the keys.

I tested Windows 7 and 10 with cmd as admin and can't make it work.

The log4jna-api uses .../EventLog/Aplication/Log4jnaTest and the demo by default uses .../EventLog\Win32LogApplication\WinLogger.

The demo has a log4j2-application.xml that can be renamed to use .../EventLog/Aplication/Log4jnaTest.

I did this to demonstrate that now yo can write anywhere in the EventLog..

@claudiow
Copy link
Contributor Author

As far as I know there is no way of running mvn without a parameter.

The nature of Maven is that you have to specify a goal or life-cycle target.

I'm waiting for this to work for you to update the change-log and readme.md

@claudiow
Copy link
Contributor Author

BTW I just added
@PluginAttribute("eventMessageFile") String eventMessageFile, @PluginAttribute("categoryMessageFile") String categoryMessageFile,
To Win32EventLogAppender as it was missing the parameters to use any file location.

The constructor uses them to create the registry values:

@dblock
Copy link
Owner

dblock commented Jun 29, 2016

Yes, I have

C:\Users\dblock\source\log4jna\dblock>java -version
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b15)
Java HotSpot(TM) Client VM (build 25.91-b15, mixed mode, sharing)

I don't think we can ask people to create registry keys for tests. You can just create them in setup of the test or something like that, and skip the tests if you're not running as admin.

@claudiow
Copy link
Contributor Author

Which version of Maven are you running?

From oshi pom: Maven minimum version 3.2.3.

I think that requiring to set the registry is not a big deal.
After all there have been enough discussions and FAQs and articles regarding the problem.
Is better that a developer or user is aware of this from the very beginning.
I would sacrifice ease of use for testing, most developer will be working in an IDE and will not be running it as administrator.
I see this problem more from the point of view of the user that is developing and testing using log4jna than for the log4jna developer who after running the test once as a admin has the configuration ready to go.
Perhaps the solution is to create an utility that creates the registry entries and you run once as an administrator.

@claudiow
Copy link
Contributor Author

I think I find where your compilation error is coming from.

You might have and old JDK prior to Java 8. Check javac -version and change your %JAVA_HOME% to the proper JDK.

Is not the version of java is the version of javac

@dblock dblock merged commit b535954 into dblock:master Jun 30, 2016
@dblock
Copy link
Owner

dblock commented Jun 30, 2016

Yep, that worked. Sorry about that, I don't do much Java development these days. Thanks for contributing this!

I think the next important step now that it's mavenized, and before trying to release to Maven central, is to get a working AppVeyor build here for future PRs. I opened #10. I found http://www.yegor256.com/2015/01/10/windows-appveyor-maven.html, and enabled the build on https://ci.appveyor.com/project/dblock/log4jna. You should be able to make pull requests and getting those to green. Would you like to give it a shot?

@dblock
Copy link
Owner

dblock commented Jun 30, 2016

Opened #11 wrt changing the namespace.

@dblock
Copy link
Owner

dblock commented Jun 30, 2016

I also opened #13 to create a RELEASING.md document, and linked one from another project that uses Maven central.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants