Friday, April 19, 2013

find and the -printf argument formats in relation with xargs -n

Directives
%k size in 1K , %b in 512-byte blocks , %s in bytes. 
%d depth in the directory tree; 0 i.e. the file is a command line argument. 
%h Leading directories of file's name (all but the last element). 
%f name with any leading directories removed (only the last element). 
%p name. 
%P File's name with the name of the command line argument under which it was found removed. 
%H Command line argument under which file was found. 
%F Type of the filesystem the file is on; this value can be used for -fstype. 
%g group name, or numeric group ID if the group has no name. 
%G numeric group ID. 
%i inode number 
%l Object of symbolic link (empty string if not a symbolic link). 
%m permission bits (in octal). 
%n Number of hard links to file. 
%u owner, or numeric user ID if the user has no name. %U numeric user ID. 
A % character followed by any other character is discarded (the other character is output).

Wednesday, April 10, 2013

Ant Mojo Debuging: turning on ant-tasks logging from a maven-plugin or command line.

Here you have a legacy ant build.xml that you would like to integrate as an Ant Mojo (which is not the same as the antrun-plugin). How can we switch on the debugging from maven on the ant side... following the tutorial we create a hello ant execution... and this results in the hello.build.xml and hello.mojos.xml. Next we skip to the "Built It! Run It!" section and change the following to our projects pom.xml that is using the hello plugin.
$ mvn org.myproject.plugins:hello-plugin:hello
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Hello Plugin 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- hello-plugin:1.0-SNAPSHOT:hello (default-cli) @ hello-plugin ---

hello:
     [echo] Hello, World
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.410s
[INFO] Finished at: Wed Apr 10 09:53:12 EDT 2013
[INFO] Final Memory: 3M/554M
[INFO] ------------------------------------------------------------------------
Now change the call and add -DantMessageLevel=[info|debug|trace].
$ mvn org.myproject.plugins:hello-plugin:hello -DantMessageLevel=debug
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Hello Plugin 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- hello-plugin:1.0-SNAPSHOT:hello (default-cli) @ hello-plugin ---
Project base dir set to: /Users/tmp
Adding reference: ant.projectHelper
Adding reference: ant.parsing.context
Adding reference: ant.targets
parsing buildfile /var/folders/kh/njhg0wmx1d74cf08gds7jclc0000gp/T/plexus-ant-component5007171426381409971.build.xml with URI = file:///var/folders/kh/njhg0wmx1d74cf08gds7jclc0000gp/T/plexus-ant-component5007171426381409971.build.xml
Setting ro project property: ant.file.null -> /var/folders/kh/njhg0wmx1d74cf08gds7jclc0000gp/T/plexus-ant-component5007171426381409971.build.xml
Project base dir set to: /Users/akaan/tmp
 +Target: 
 +Target: hello
Adding reference: project
Adding reference: session
Adding reference: mojoExecution
Setting ro project property: messageLevel -> debug
Setting ro project property: basedir -> /Users/tmp
Build sequence for target(s) `hello' is [hello]
Complete build sequence is [hello, ]

hello:
     [echo] Hello, World
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.413s
[INFO] Finished at: Wed Apr 10 09:55:09 EDT 2013
[INFO] Final Memory: 3M/554M
[INFO] ------------------------------------------------------------------------
Or if you need to pass the configuration item in the plugin definition itself use messageLevel.
<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.myproject.tests</groupId>
  <artifactId>hello-plugin-tests</artifactId>
  <version>1.0</version>
  
  <name>Test Project</name>
  
  <build>
    <plugins>
      <plugin>
        <groupId>org.myproject.plugins</groupId>
        <artifactId>hello-plugin</artifactId>
        <version>1.0-SNAPSHOT</version>
        
        <configuration>
          <name>John</name>


          <messageLevel>debug</messageLevel> 


        </configuration>
        
        <executions>
          <execution>
            <phase>validate</phase>
            <goals>
              <goal>one</goal>
              <goal>two</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>